Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There are n applications on this phone. Thor is fascinated by this phone. He has only one minor issue: he can't count the number of unread notifications generated by those applications (maybe Loki put a curse on it so he can't).c++
q events are about to happen (in chronological order). They are of three types:app
Please help Thor and tell him the number of unread notifications after each event. You may assume that initially there are no notifications in the phone.ide
The first line of input contains two integers n and q (1 ≤ n, q ≤ 300 000) — the number of applications and the number of events to happen.this
The next q lines contain the events. The i-th of these lines starts with an integer typei — type of the i-th event. If typei = 1 or typei = 2then it is followed by an integer xi. Otherwise it is followed by an integer ti (1 ≤ typei ≤ 3, 1 ≤ xi ≤ n, 1 ≤ ti ≤ q).spa
Print the number of unread notifications after each event.code
3 4
1 3
1 1
1 2
2 3
1
2
3
2
4 6
1 2
1 4
1 2
3 3
1 3
1 3
1
2
3
0
1
2
In the first sample:blog
In the second sample test:three
題意:ci
讓你模擬一下這個產生信息和看信息的過程get
題解:
首先咱們看到一共只有30W個操做,意思就是操做信息就最多隻有30W次,因此咱們開一個vector 來存每一個APP的信息編號,set來存未讀信息的編號,遇到2操做就在set裏刪除,由於最多隻有30W的信息,因此怎麼也不會超時,遇到3操做就直接在set裏把小於t的編號信息所有刪掉
1 #include<bits/stdc++.h> 2 #define pb push_back 3 #define F(i,a,b) for(int i=a;i<=b;++i) 4 using namespace std; 5 typedef pair<int,int>P; 6 7 const int N=3e5+7; 8 int n,q,x,y,ed,v[N]; 9 vector<int>Q[N]; 10 set<int>cnt; 11 set<int>::iterator it; 12 13 int main(){ 14 scanf("%d%d",&n,&q); 15 F(i,1,q) 16 { 17 scanf("%d%d",&x,&y); 18 if(x==1)Q[y].pb(++ed),cnt.insert(ed); 19 else if(x==2){ 20 int sz=Q[y].size(); 21 F(j,0,sz-1)cnt.erase(Q[y][j]); 22 Q[y].clear(); 23 } 24 else{ 25 int ved=0; 26 for(it=cnt.begin();it!=cnt.end();it++) 27 { 28 if(*it>y)break; 29 v[++ved]=*it; 30 } 31 F(j,1,ved)cnt.erase(v[j]); 32 } 33 printf("%d\n",cnt.size()); 34 } 35 return 0; 36 }