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 ...
随机推荐
- [一波低姿势的usaco除草记]
总共花了一个月左右 把一份usaco的总结刷了一遍 应该有一百四十多道题 在此纪念一下 总体来说 发现自己基础不是很稳 基本贪心和一些堆的做法还是有点弱鸡 一些dp还是有点弱 但是数据结构题几乎都可以 ...
- java MD5 加密
使用javaMD5.jar ========================================== 使用java的security类 ========================== ...
- Genymotion下载失败解决方法
Genymotion下载虚拟机版本时会很慢,而且经常下载失败 解决方法如下: 1.先去选择下载你需要的版本,之后会下载(很慢),或者失败. 2.到C:\Users\yourname\AppData\L ...
- 解码红外遥控信号——使用遥控器的按键来调节LED的亮度
程序开始时,提示遥控键0~4的代码,然后程序通过设置LED的亮度来对被按下的按钮作出响应,以0关闭LED,1~4提供增加的亮度. 代码如下:(需要使用IRremote库,可在库管理中搜索该库进行下载后 ...
- JavaScript简单的一些....
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- edittext设置为密文显示
et_msg.setInputType(InputType.TYPE_CLASS_TEXT |InputType.TYPE_TEXT_VARIATION_PASSWORD);
- URL中的#
作者:阮一峰 http://www.ruanyifeng.com/blog/2011/03/url_hash.html 一.#的涵义 #代表网页中的一个位置.其右面的字符,就是该位置的标识符.比如 ...
- CodeForces 340E Iahub and Permutations
容斥原理,组合数. 找出有$cnt$个数字还有没放,那么总方案数就是$cnt!$. 总方案数里面包含了正确的和非正确的,我们需要将非正确的删去. 先删去$1$个数字$a[i]=i$的情况,发现会多删, ...
- [UWP小白日记-5]转换MVA学院的XML字幕为SRT
开源地址:第二版开源地址GIT 暂时用不了了,在最新的WIN10 10586.494系统上回闪退,正在酝酿第二版 O(∩_∩)O哈哈~ 新版已经完工:第二版 地方MVA上好多教程,但是微软的所有中国网 ...
- 观察者模式 C++11
#include <functional> #include <vector> #include <algorithm> #include <iostream ...