Codeforces 705C Thor (模拟)
来源:互联网 发布:淘宝漏洞1元买东西 编辑:程序博客网 时间:2024/05/22 00:47
http://www.codeforces.com/contest/705/problem/C
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.
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 = 2 then 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
题意简化相当于:
有三种操作,第一种操作是 将 x值 插入到容器的末尾;第二种操作是 将 容器中 的 x值 全部标记; 第三种操作是 将容器中前 x 个数标记。 标记过得可重复标记。问每个操作做完后有多少个数没有被标记。
解题思路:
用容器直接模拟,T了好久。加优化也T。
后来开个pre[]数组记录x值得前面一个x值在哪个地方。
这种pre[] , next[]的方法要熟记…
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int N = 3*1e5 + 100;int arr[N], tail[N], pre[N], vis[N];int main(){ int n,q,id = 0,sum=0,last = 0; scanf("%d%d",&n,&q); memset(tail,-1,sizeof(tail)); memset(pre,-1,sizeof(pre)); while(q--) { int op,x; scanf("%d%d",&op,&x); if(op==1) { pre[++id] = tail[x]; tail[x] = id; sum++; } else if(op==2) { int tmp = tail[x]; while(tmp!=-1 && !vis[tmp]) { vis[tmp] = true; tmp = pre[tmp]; sum--; } } else { for(int i = last+1; i<=x;i++) { if(!vis[i]) { sum--; vis[i] = true; } } last = max(last,x); } printf("%d\n",sum); } return 0;}
- Codeforces 705C Thor (模拟)
- CodeForces 705C Thor (模拟)
- 【模拟】Codeforces 704A & 705C Thor
- Codeforces Round #366 (Div. 2) C. Thor (模拟)
- Codeforces Round #366 (Div. 2) C. Thor(模拟)
- Codeforces Round #366 (Div. 2) C. Thor (模拟)*
- Codeforces Round #366 (Div. 2) C. Thor (队列模拟)
- 【Codeforces Round #366 Div. 2】 705C Thor
- Codeforces #366(Div.2) C. Thor【思维】
- Codeforces Round #366 (Div. 2) C. Thor
- Codeforces Round #366 (Div. 2) C. Thor
- Codeforces Round #366 (Div. 2)-C. Thor
- Codeforces Round #366 (Div. 2) C.Thor
- Codeforces 704A Thor (脑洞题)
- 【CodeForces】704A - Thor(队列,详解)
- Codeforces Round #366 (Div. 2) C. Thor 数据结构、队列优化
- Codeforces-704A-Thor
- 【codeforces 704A Thor】
- TO_CHAR(DATE,FORMAT)详解
- c++中的std::shared_ptr和std::weak_ptr
- 多线程的使用(2) - NSOperation和NSOperationQueue
- Error:Failed to resolve: com.android.support:support-annotations:23.3.0
- day10_python2和python3的继承
- Codeforces 705C Thor (模拟)
- OpenSceneGraph实现的NeHe OpenGL教程 - 第二十八课
- jzoj 3076. 【备战NOIP2012图论专项模拟试题】位图
- php 自带过滤和转义函数
- TypeError: 'str' object is not callable
- 基于R-CNN的物体检测-CVPR 2014
- 通过ip地址及端口连接服务器
- php高手干货【必看】
- OpenSceneGraph实现的NeHe OpenGL教程 - 第二十九课