1 solutions
-
0
依据题意直接进行模拟即可。
我们对于每一个应用都维护一个队列,之后只需记录消息的编号,并且记录每一个消息是属于哪一个应用即可。
对于每个输入都进行模拟,这样每条消息只会进队出队一次。
#include <bits/stdc++.h> using namespace std; inline int read() { int x=0; int f=1; char ch=getchar(); while(!isdigit(ch)) {if(ch=='-')f=-1; ch=getchar();} while(isdigit(ch)) {x=x*10+ch-'0'; ch=getchar();} return x*f; } const int MAXN = 300005; queue<int> a[MAXN]; int num[MAXN]; int n,m,q,ans,lst; int main(int argc, char const *argv[]) { n=read(); q=read(); for(int i=1; i<=q; i++) { int opt=read(),t=read(); if(opt==1) ans++,num[++m]=t,a[t].push(m); else if(opt==2) while(!a[t].empty()) a[t].pop(),ans--; else { while(lst<t) { lst++; if(!a[num[lst]].empty()) if(a[num[lst]].front()<=lst) a[num[lst]].pop(),ans--; } } printf("%d\n",ans); } return 0; }
Information
- ID
- 678
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 10
- Tags
- (None)
- # Submissions
- 106
- Accepted
- 2
- Uploaded By