Codeforces 705C Thor

Source: Internet
Author: User

Open 30W Vector The numbers are sorted, each type of number opens a pointer p, records which one has been read, and can also open a priority queue to maintain these pointer p.

#pragmaComment (linker, "/stack:1024000000,1024000000")#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<vector>#include<map>#include<Set>#include<queue>#include<stack>#include<iostream>using namespaceStd;typedefLong LongLL;Const DoublePi=acos (-1.0), eps=1e-8;voidFile () {freopen ("D:\\in.txt","R", stdin); Freopen ("D:\\out.txt","W", stdout);} InlineintRead () {Charc = GetChar (); while(!isdigit (c)) C =GetChar (); intx =0;  while(IsDigit (c)) {x = x *Ten+ C-'0'; c =GetChar ();} returnx;}Const intmaxn=300000+Ten; Vector<int>G[MAXN];intN,q,sz,p[maxn],ans;structx{intNum,now,pos,idx; BOOL operator< (ConstX &a)Const {        returnIdx>A.idx; } X (intNumintNow,intPosintIDX) {num=num; now=now; pos=pos,idx=Idx;}}; Priority_queue<X>Q;intMain () {scanf ("%d%d",&n,&q); SZ=0; ans=0; memset (p,-1,sizeofp);  for(intI=1; i<=q;i++)    {        intT,d; scanf"%d%d",&t,&d); if(t==1)        {            ++sz; if(P[d]==g[d].size ()-1) {Q.push (X (d,p[d],p[d)+1, SZ)); }g[d].push_back (SZ); Ans++; }        Else if(t==2) {ans=ans-(G[d].size ()-1-P[d]); P[D]=g[d].size ()-1; }        Else        {             while(! Q.empty () && (). idx<=d) {X ();                Q.pop (); if(<p[h.num])Continue; Ans=ans-(h.pos-P[h.num]); P[h.num]=H.pos; if(p[h.num]+1<g[h.num].size ()) Q.push (X (h.num,p[h.num],p[h.num)+1, g[h.num][p[h.num]+1])); }} printf ("%d\n", ans); }    return 0;}

Codeforces 705C Thor

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.