Title: Here
Test instructions: N app,q operation, when the operand type is 1 indicates y this app pushes you a message, when the operand type is 2 indicates that Y this app has pushed all the messages are read, when the operand is 3
Indicates that the pre-pushed (in chronological order of push) Y messages are read again (regardless of what has been read in the previous Y-message, read it again), and ask what is the number of unread messages per operation?
Use the queue to simulate the good, remember that every time you want to output the total number of messages that are not read by all the app, do not think too thin, read the mark on the line, always think this will time out, but I think this is the third problem of 2, 1
The first question, should not so the card time, all have the courage to write.
1 //The queue simply records the CAs and does not need to record Y2#include <cstdio>3#include <cstring>4#include <iostream>5#include <algorithm>6#include <cstring>7#include <queue>8 using namespacestd;9 Ten Const intM = 3e5 +Ten; One BOOLVi[m]; Aqueue<pair<int,int> >Q[m]; - - intMain () the { - intn,m; - Long Longans=0; -scanf"%d%d",&n,&m); + intpo=1, cas=0, r=0; -Memset (VI,false,sizeof(vi)); + while(m--) A { at intx, y; -scanf"%d%d",&x,&y); - if(x==1) Q[y].push (make_pair<int,int> (Y,++cas)), ans++; - Else if(x==2) { - while(!q[y].empty ()) - { in intw=Q[y].front (). Second; - if(vi[w]==false) ans--; tovi[w]=true; + Q[y].pop (); - } the } * Else { $ for(intI=po; I<=min (Cas,y); i++)Panax Notoginseng { - if(vi[i]==false) ans--; thevi[i]=true; + } Apo=Max (po,y); the } +printf"%i64d\n", ans); - } $ return 0; $}
Codeforces 704A (queue emulation) Thor