C. Thor
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

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:

  1. Application x generates a notification (this new notification is unread).
  2. Thor reads all notifications generated so far by application x (he may re-read some notifications).
  3. 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.

Input

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).

Output

Print the number of unread notifications after each event.

Examples
input
3 4
1 3
1 1
1 2
2 3
output
1
2
3
2
input
4 6
1 2
1 4
1 2
3 3
1 3
1 3
output
1
2
3
0
1
2
Note

In the first sample:

  1. Application 3 generates a notification (there is 1 unread notification).
  2. Application 1 generates a notification (there are 2 unread notifications).
  3. Application 2 generates a notification (there are 3 unread notifications).
  4. Thor reads the notification generated by application 3, there are 2 unread notifications left.

In the second sample test:

  1. Application 2 generates a notification (there is 1 unread notification).
  2. Application 4 generates a notification (there are 2 unread notifications).
  3. Application 2 generates a notification (there are 3 unread notifications).
  4. Thor reads first three notifications and since there are only three of them so far, there will be no unread notification left.
  5. Application 3 generates a notification (there is 1 unread notification).
  6. 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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. Codeforces Round #366 Div.2[11110]

    这次出的题貌似有点难啊,Div.1的Standing是这样的,可以看到这位全站排名前10的W4大神也只过了AB两道题. A:http://codeforces.com/contest/705/prob ...

  5. Codeforces Round #366 (Div. 2)

    CF 复仇者联盟场... 水题 A - Hulk(绿巨人) 输出love hate... #include <bits/stdc++.h> typedef long long ll; co ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. Codeforces Round #366 (Div. 2) B 猜

    B. Spider Man time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

随机推荐

  1. 【NOIP2013】Day2不完全题解+代码

    T1 直接递归区间,从1-n开始,找到这个区间中的最小值然后将区间里的所有值都减去这个最小值 以被减去最小值之后的零点为分段分别递归处理即可. #include <algorithm> # ...

  2. win7、win8.1淡绿色护眼模式设置

    Win7设置: 右击桌面 -> 个性化 -> 窗口颜色 -> 高级外观设置 选中 -> 项目:窗口     颜色:其他 修改:色调  饱和度 亮度 红  绿  蓝 添加到自定义 ...

  3. TypeUtils -- Object 转为 强类型

    public static class TypeUtils { /// <summary> /// Object 转为 强类型 /// </summary> public st ...

  4. SQL 判断 ‘表,存储过程,函数 ...’ 已是否存在

    下面为您介绍sql下用了判断各种资源是否存在的代码,需要的朋友可以参考下,希望对您学习sql的函数及数据库能够有所帮助.库是否存在if exists(select * from master..sys ...

  5. 删除 CentOS7 更新后产生的多余的内核

    今天更新完系统的内核,重启电脑时发现突然多了一个启动项,想删除多余的启动项,在上网查找后,找到了下面的方法,经过测试,是完全可行的.自己写下来,以便以后用到.1.# uname -a 列出系统中正在使 ...

  6. TCP TIME_WAIT详解

    转自:http://m.blog.chinaunix.net/uid-20384806-id-1954363.html TIME_WAIT状态 TCP要保证在所有可能的情况下使得所有的数据都能够正确被 ...

  7. python连接mysql、oracle小例子

    import  MySQLdbimport  cx_Oracle   as  oraimport  pandas  as  pdfrom    sqlalchemy import create_eng ...

  8. 使用curl来调试你的应用

    我们在客户端开发过程中总免不了和后端进行api对接,有时候需要对返回的数据格式进行调试,有时候每次运行客户端来发送请求,这个未免效率太低,这里就来介绍一个好用的工具--curl. curl curl是 ...

  9. iOS Plugins

    iOS Plugins This section provides details for how to implement native plugin code on the iOS platfor ...

  10. Comparer<T> IComparer<T> IComparable<T>

    Comparer<T>.Default Property Comparer<T>.Default doesn't use your FooComparer class. It ...