Codeforces Round #366 (Div. 2)-C. Thor

原题链接

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

定义vector<int> v, v[i]记录第i个app产生通知的时间,时间按照小到大顺序存放,cnt[i]表示第i个app的通知已经看了多少个

set<Node>里面存的是未看的通知,Node由通知的时间,和产生通知的app组成.set里面的元素按照时间顺序排列

1.对于第一个操作,直接在v,和s中插入对应通知即可

2.对第二个操作,对于app j的所有通知,找到v[j]未看的通知,在set中删除即可

3.对第三种操作,检查set中第一个元素的时间是否小于等于t,若是则删除 ,并且更新cnt[],不断进行下去

#include <bits/stdc++.h>
#define maxn 300005
#define MOD 1000000007
using namespace std;
typedef long long ll;

struct Node{
	Node(){
	}
	Node(int a, int b){
		t = a;
		p = b;
	}
	friend bool operator < (const Node&a, const Node&b){
		return (a.t == b.t && a.p < b.p) || a.t < b.t;
	}
	int t, p;
};
vector<int> v[maxn];
int cnt[maxn];
set<Node> s;
int main(){
	
	//freopen("in.txt", "r", stdin);
	int n, q, tt = 1, ans = 0;
	
	scanf("%d%d", &n, &q);
	for(int i = 1; i <= q; i++){
		int k1, k2;
		scanf("%d%d", &k1, &k2);
		if(k1 == 1){
			v[k2].push_back(tt);
			s.insert(Node(tt++, k2));
			ans++;
		}
		else if(k1 == 2){
			if(cnt[k2] != v[k2].size()){
				for(int j = cnt[k2]; j < v[k2].size(); j++){
					s.erase(Node(v[k2][j], k2));
				}
				ans -= v[k2].size() - cnt[k2];
				cnt[k2] = v[k2].size();
			}
		}
		else{
			set<Node> ::iterator iter = s.begin();
			if(iter -> t <= k2){
				while(!s.empty() && iter -> t <= k2){
					cnt[iter->p]++;
					s.erase(*iter);
					ans--;
					iter = s.begin();
				}
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值