题目:这里

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

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

 

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

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

 1 //队列只要记录cas就行了,并不需要记录y
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<iostream>
 5 #include<algorithm>
 6 #include<cstring>
 7 #include<queue>
 8 using namespace std;
 9 
10 const int M = 3e5 + 10;
11 bool vi[M];
12 queue<pair<int,int> >q[M];
13 
14 int main()
15 {
16     int n,m;
17     long long ans=0;
18     scanf("%d%d",&n,&m);
19     int po=1,cas=0,r=0;
20     memset(vi,false,sizeof(vi));
21     while (m--)
22     {
23         int x,y;
24         scanf("%d%d",&x,&y);
25         if (x==1) q[y].push(make_pair<int,int>(y,++cas)),ans++;
26         else if (x==2) {
27             while (!q[y].empty())
28             {
29                 int w=q[y].front().second;
30                 if (vi[w]==false) ans--;
31                 vi[w]=true;
32                 q[y].pop();
33             }
34         }
35         else {
36             for (int i=po ; i<=min(cas,y) ; i++)
37             {
38                  if (vi[i]==false) ans--;
39                  vi[i]=true;
40             }
41             po=max(po,y);
42         }
43         printf("%I64d\n",ans);
44     }
45     return 0;
46 }

 

posted on 2016-08-13 19:54  蜘蛛侦探  阅读(411)  评论(0编辑  收藏  举报