题目大意, Thor(雷神)初来地球, 洛基给了他一个smartphone(智能机). 手机上有n个app. Thor对这个手机十分感兴趣. 有一点疑惑是, 他无法统计由这些app产生的未读的信息(或许的洛基下的诅咒---什么鬼哦).
现在有q个事件发生, 分为3种类型.
1. app x 获得一个未读信息
2. 读取 app x 的所有信息
3. Thor 将会读取由app产生的前t条信息(notifications generated in first t events of the first type). 保证至少有t个第一种事件. Please note that he doesn't read first t unread notifications, he just reads the very first t notifications generated on his phone and he may re-read some of them in this operation.
题意不是很好理解(So poor in english), 主要是第三种类型····
先入先出...队列
用一个队列来记录事件(编号加内容)
用一个数组来标记事件是否访问过
再用一个队列(也可以用其他的方法)来记录app的信息
然后模拟...
#include<cstdio>#include<queue>usingnamespacestd;
int n, q, t, a;
int s;
int f[300001];
queue<int> Q[300001];
queue< pair<int, int> >time;
int main()
{
scanf("%d %d", &n, &q);
int p = 1;
while ( q -- )
{
scanf("%d %d", &t, &a);
if ( t == 1 )
{
Q[a].push(p);
time.push(make_pair(p, a));
s ++;
p ++;
}
elseif ( t == 2 )
{
while ( !Q[a].empty() )
{
f[Q[a].front()] = 1;
Q[a].pop();
s --;
}
}
else
{
while ( !time.empty() && time.front().first <= a )
{
if ( !f[time.front().first] )
{
Q[time.front().second].pop();
s --;
}
time.pop();
}
}
printf("%d\n", s);
}
return0;
}