题干:

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

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

题目大意:

第一行两个整数n,m,代表n个软件,m次操作。(1 ≤ n, q ≤ 300 000)

接下来m行:
1 x :软件 x 产生了一条未读信息。
2 x: 软件 x 的所有信息都被读了。
3  t: 前 t 条产生的信息都被读了。注意是前t条,不是未读的前t条,已读的也算在t条中。

解题报告:

本来想用个双向链表来啊维护出现过的所有信息,但是发现它可以支持快速的删除一个元素,但是对于查找前t条信息比较鸡肋,甚至还要拿个并查集去搞,比较麻烦,于是换了各项性能都还说的过去的set,直接二分找前t条信息就可以了,这样最后的答案就是set的大小。

注意不能让标号直接等于i,因为第i个操作不一定是产生一天新的信息。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define FF first
#define SS second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 5e5 + 5;
int n,m,last,id;
set<int> ss[MAX],q;//存链表,因为值直接就是索引就可以了,不需要单独弄链表了int main()
{cin>>n>>m;for(int op,x,i = 1; i<=m; i++) {scanf("%d%d",&op,&x);if(op == 1) {id++;ss[x].insert(id);q.insert(id);}if(op == 2) {for(auto idx : ss[x]) {if(q.find(idx) != q.end())q.erase(idx);}ss[x].clear();}if(op == 3) {auto upp = q.upper_bound(x),down = q.begin();q.erase(down,upp);last = max(last,x);}printf("%d\n",q.size());}return 0 ;
}

【CodeForces - 705C】Thor(模拟,STLset优化链表)相关推荐

  1. Codeforces 786B Legacy (线段树优化建图)

    Codeforces 786B Legacy (线段树优化建图) 题意:\(n\)个点,有\(3\)种连边操作:1.将\(u\)指向\(v\):2.将\(v\)指向编号在区间\([l,r]\)的点:3 ...

  2. Promodel®模拟和优化套装加速企业绩效改善 功能介绍

    采用Promodel®模拟和优化套装加速企业绩效改善,消除风险! Promodel®仿真模拟和优化套装是业内先进的离散事件系统仿真软件,由ProModel公司于1996年开发.它可以构造多种生产.物流 ...

  3. CodeForces - 1491E Fib-tree(模拟)

    题目链接:点击查看 题目大意:给出一棵树,问是否为斐波那契树.斐波那契树的定义是,树的大小为斐波那契数列的其中一项,且可以通过删除掉一条边使其拆分的两个子树也为斐波那契树 题目分析:需要观察到,大小为 ...

  4. R语言几何布朗运动 GBM模拟股票价格优化建立期权定价概率加权收益曲线可视化

    最近我们被客户要求撰写关于几何布朗运动的研究报告,包括一些图形和统计输出. 对于模拟股票价格,几何布朗运动 (GBM) 是 事实上的首选 模型. 它有一些很好的属性,通常与股票价格一致,例如对数正态分 ...

  5. Codeforces 1408 D. Searchlights(优化DP、思维)

    整理的算法模板合集: ACM模板 传送门 DP的思想,因为题目中有两个维度,数据达到了1e6,所以我们直接开二维数组显然不太恰当,而且我们的答案不好选取,我们可以使用一个技巧,开一维数组,用DP的下标 ...

  6. codeforces 719C (复杂模拟-四舍五入-贪心)

    题目链接:http://codeforces.com/problemset/problem/719/C 题目大意: 留坑... 转载于:https://www.cnblogs.com/A--Q/p/5 ...

  7. 模拟实现单链表(三级)

    讲了顺序表的实现呢,下面我们来讲单链表每个节点包括两部分,哪两部分,一部分是存放数据的,另一部分是存放地址的,存放下一个节点的地址,这叫单链表,单链表也就是单向链表,有单向的就应该有双向的,双向表该怎 ...

  8. Codeforces 67A【模拟】

    题意: 给一个字符串代表相邻学生的比较,L代表左边多,R表示右边多,=表示左右相等. 保证每个人拿糖>=1,在分糖最少的情况下,输出每个学生所分得的糖. 思路: 模拟一下,第一个人一开始拿1个, ...

  9. CodeForces - 786C——二分+模拟?

    [题目描述] Rick and Morty want to find MR. PBH and they can't do it alone. So they need of Mr. Meeseeks. ...

最新文章

  1. 在layui中使用ajax传值给后台,浅谈layui 数据表格前后台传值的问题
  2. soalris小記...
  3. obs 直播 多路推流插件 简介
  4. Java连接数据库(2)
  5. linux图形化应用程序快捷方式制作方法
  6. 你绝对能懂的“机器学习”(五)
  7. 网易云信,发送验证码短信C#版代码
  8. 机器学习框架ML.NET学习笔记【1】基本概念与系列文章目录
  9. MySQL基础篇(04):存储过程和视图,用法和特性详解
  10. 【HDU5656】CA Loves GCD,容斥思想与乱搞
  11. 你以为你懂MySQL索引?阿里的面试官:你还太嫩!
  12. 【系统架构】VC 开发辅助工具大收集
  13. npm install 报错:node-pre-gyp ERR! 问题解决
  14. Java解决高并发下商品库存更新
  15. 规范使用地图,从规范制图开始
  16. 电商常见业务场景分析思路(持续更新中......)
  17. 区块链实现的关键技术_保险中的区块链:实现关键的增长机会
  18. Aspnet Mvc 前后端分离项目手记(二)关于token认证
  19. SAP 获取不同币种间的汇率 RFC BAPI_EXCHANGERATE_GETDETAIL
  20. win7家庭版桌面没有计算机图标,Win7 home basic家庭普通版显示桌面图标的方法

热门文章

  1. 集合附加属性(HACK)
  2. 【数据结构与算法】图
  3. wpf的listbox循环数据滚动_滚动版 CentOS Stream 和 Fedora 的关系
  4. 枚举命名规范_UE4 C++基础教程 - 编码规范
  5. 计算机数学基础模拟试题,计算机数学基础(A)模拟试题.doc
  6. 自动化测试工具selenium python_Selenium自动化测试工具使用方法汇总
  7. php搭建的网站空白,使用phpstudy搭建dedecms网站后台页面空白解决方法
  8. 中职计算机说课稿三篇,精选中职计算机说课稿三篇-20210609060707.docx-原创力文档...
  9. Linux编程练习 --多线程4--条件变量
  10. java jni librtmp_librtmp 编译集成