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 () &&q.top (). idx<=d) {X h=Q.top (); Q.pop (); if(H.now<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