Codeforces Round #366 (Div. 2)_C. Thor
2 seconds
256 megabytes
standard input
standard output
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).
q events are about to happen (in chronological order). They are of three types:
- Application x generates a notification (this new notification is unread).
- Thor reads all notifications generated so far by application x (he may re-read some notifications).
- Thor reads the first t notifications generated by phone applications (notifications generated in first t events of the first type). It's guaranteed that there were at least t events of the first type before this event. 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.
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.
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.
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).
Print the number of unread notifications after each event.
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:
- Application 3 generates a notification (there is 1 unread notification).
- Application 1 generates a notification (there are 2 unread notifications).
- Application 2 generates a notification (there are 3 unread notifications).
- Thor reads the notification generated by application 3, there are 2 unread notifications left.
In the second sample test:
- Application 2 generates a notification (there is 1 unread notification).
- Application 4 generates a notification (there are 2 unread notifications).
- Application 2 generates a notification (there are 3 unread notifications).
- Thor reads first three notifications and since there are only three of them so far, there will be no unread notification left.
- Application 3 generates a notification (there is 1 unread notification).
- Application 3 generates a notification (there are 2 unread notifications).
题意:
让你模拟一下这个产生信息和看信息的过程
题解:
首先我们看到一共只有30W个操作,意思就是操作信息就最多只有30W次,所以我们开一个vector 来存每个APP的信息编号,set来存未读信息的编号,遇到2操作就在set里删除,因为最多只有30W的信息,所以怎么也不会超时,遇到3操作就直接在set里把小于t的编号信息全部删掉
#include<bits/stdc++.h>
#define pb push_back
#define F(i,a,b) for(int i=a;i<=b;++i)
using namespace std;
typedef pair<int,int>P; const int N=3e5+;
int n,q,x,y,ed,v[N];
vector<int>Q[N];
set<int>cnt;
set<int>::iterator it; int main(){
scanf("%d%d",&n,&q);
F(i,,q)
{
scanf("%d%d",&x,&y);
if(x==)Q[y].pb(++ed),cnt.insert(ed);
else if(x==){
int sz=Q[y].size();
F(j,,sz-)cnt.erase(Q[y][j]);
Q[y].clear();
}
else{
int ved=;
for(it=cnt.begin();it!=cnt.end();it++)
{
if(*it>y)break;
v[++ved]=*it;
}
F(j,,ved)cnt.erase(v[j]);
}
printf("%d\n",cnt.size());
}
return ;
}
Codeforces Round #366 (Div. 2)_C. Thor的更多相关文章
- Codeforces Round #366 (Div. 2) C Thor(模拟+2种stl)
Thor 题意: 第一行n和q,n表示某手机有n个app,q表示下面有q个操作. 操作类型1:app x增加一条未读信息. 操作类型2:一次把app x的未读信息全部读完. 操作类型3:按照操作类型1 ...
- Codeforces Round #366 (Div. 2) C. Thor (模拟)
C. Thor time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #366 Div.2[11110]
这次出的题貌似有点难啊,Div.1的Standing是这样的,可以看到这位全站排名前10的W4大神也只过了AB两道题. A:http://codeforces.com/contest/705/prob ...
- Codeforces Round #366 (Div. 2)
CF 复仇者联盟场... 水题 A - Hulk(绿巨人) 输出love hate... #include <bits/stdc++.h> typedef long long ll; co ...
- Codeforces Round #366 (Div. 2) C 模拟queue
C. Thor time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...
- Codeforces Round #366 (Div. 2) A , B , C 模拟 , 思路 ,queue
A. Hulk time limit per test 1 second memory limit per test 256 megabytes input standard input output ...
- Codeforces Round #366 (Div. 2) B
Description Peter Parker wants to play a game with Dr. Octopus. The game is about cycles. Cycle is a ...
- Codeforces Round #366 (Div. 2) B 猜
B. Spider Man time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
随机推荐
- action中list传到JSP中取不到值的问题
今天遇到了这个问题 action中list传到JSP中取不到值 搞了半天是因为我在JSP中取值的的时候 <s:iterator value="shlist" var=&qu ...
- mac下 使用 versions版本控制工具 修复游戏bug过程
1,首先拥有游戏源代码文件,修复bug之前先使用versions工具进行更新: 2,查找指定的bug之前,先运行游戏,在源代码中觉得是bug的地方打个断点,然后运行游戏的对应有bug的地方,看是否会有 ...
- js 设计模式-接口
js模拟java接口检测函数:确保子类实现接口中的方法:(出自js设计模式) 上代码: <script type="text/javascript" > <%-- ...
- 报错找不到org.apache,http...的解决办法
在build.gradle中加入 android { useLibrary 'org.apache.http.legacy' }
- POJ 2484 A Funny Game
博弈. $n>=3$,后手赢,否则先手赢. #pragma comment(linker, "/STACK:1024000000,1024000000") #include& ...
- USACO 3.3 Shopping Offers
Shopping OffersIOI'95 In a certain shop, each kind of product has an integer price. For example, the ...
- HTTP 错误 403.14 - Forbidden的解决办法
错误: HTTP 错误 403.14 - ForbiddenWeb 服务器被配置为不列出此目录的内容. 原因: 出现这个错误,是因为默认文档中没有增加index.aspx导致的. 解决方法: 打开 ...
- 【noi openjudge题解】最低通行费
这道题完全没有必要去计算限制时间,把时间当做一个参数来做就行了.知道了这一点之后就可以直接使用DP求解了 #include <algorithm> #include <iostrea ...
- Java基本知识
一.I/O 分字节流和字符流 字节流由InputStream和OutputStream读入和写入 DataInputStream继承自FilterInputStream,可以读取基本数据类型(char ...
- x264宏块及子块划分方式
1 宏块划分方式 一副图像(帧,非场图像,x264支持宏块级场编码,这里以帧图像为例说明)按从左到右.从上到下16x16的方式划分宏块,对于图像宽度不是16的倍数的情况,会扩展至16的倍数,然后通过s ...