codeforces 704A (队列模拟) Thor

时间:2023-03-09 21:35:51
codeforces 704A (队列模拟) Thor

题目:这里

题意:n个app,q个操作,当操作数type为1的时候表示y这个app推送了你一条消息,当操作数type为2的时候表示将y这个app已推送的所有消息都读完,当操作数为3的时候

表示将已经推送的前(按推送的时间顺序)y条消息再读一遍(不管这前y条消息中有没有读过的,都再读一遍),问每次操作的时候的未读的消息数是多少?

用队列来模拟就好,记得每次要输出的是所有app的没有读过的消息的总数就行,不要想的太细,把读过的标记一下就行,总是觉得这个会超时,但是一想这才是2的第三题,1

的第一题,应该不会那么卡时间,所有就大着胆子写了。

 //队列只要记录cas就行了,并不需要记录y
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std; const int M = 3e5 + ;
bool vi[M];
queue<pair<int,int> >q[M]; int main()
{
int n,m;
long long ans=;
scanf("%d%d",&n,&m);
int po=,cas=,r=;
memset(vi,false,sizeof(vi));
while (m--)
{
int x,y;
scanf("%d%d",&x,&y);
if (x==) q[y].push(make_pair<int,int>(y,++cas)),ans++;
else if (x==) {
while (!q[y].empty())
{
int w=q[y].front().second;
if (vi[w]==false) ans--;
vi[w]=true;
q[y].pop();
}
}
else {
for (int i=po ; i<=min(cas,y) ; i++)
{
if (vi[i]==false) ans--;
vi[i]=true;
}
po=max(po,y);
}
printf("%I64d\n",ans);
}
return ;
}