题目链接:

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 题意: 现在给n个应用,三种操作,第一种是一个应用产生一个消息,第二个是读完这种应产生的所有的消息,第三个是读完前t个消息; 思路: 用队列模拟一下; AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>
#include <stack>
#include <map> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
if(!p) { puts("0"); return; }
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
} const LL mod=1e9+7;
const double PI=acos(-1.0);
const LL inf=1e18;
const int N=3e5+10;
const int maxn=2e3+14;
const double eps=1e-12; int n,q,x,type,num[N];
int a[N],vis[N];
queue<int>qu[N];
int main()
{
read(n);read(q);
int sum=0,pre=0,cnt=0;
For(i,1,q)
{
read(type);read(x);
if(type==1)
{
num[x]++;
sum++;
a[++cnt]=x;
qu[x].push(cnt);
}
else if(type==2)
{
while(!qu[x].empty())
{
int fr=qu[x].front();
qu[x].pop();
vis[fr]=1;
}
sum-=num[x];
num[x]=0;
}
else
{
for(int i=pre+1;i<=x;i++)
{
if(vis[i])continue;
int temp=a[i];
qu[temp].pop();
num[temp]--;
sum--;
vis[i]=1;
}
pre=max(pre,x);
}
printf("%d\n",sum);
} return 0;
}

  

最新文章

  1. Mac OS 后台服务注册
  2. iOS仿网易新闻栏目拖动重排添加删除效果
  3. css使input中的值自动变大写
  4. SocketTcpServer
  5. LPSTR、LPCSTR、LPTSTR、LPCTSTR、LPWSTR及LPCWSTR的意义及区别
  6. jquery mobile自己定义webapp开发实例(一)——前言篇
  7. 二分图匹配之KM求二分图最佳匹配算法
  8. C#事物
  9. 关于Java常见的误解
  10. 如何在Raspberry Pi 3B中安装RASPBIAN
  11. iOS9 ReplayKit录制视频
  12. git撤销commit-hard
  13. LOJ #6053. 简单的函数
  14. javax.crypto.BadPaddingException: Given final block not properly padded解决方案
  15. npm常用功能
  16. 网页排版的时候不要忘了table标签
  17. Tomcat改端口号;修改访问路径,以及配置Context 标签以后Tomcat启动不了
  18. android中的数据库操作(SQLite)
  19. Spring学习笔记--自动装配Bean属性
  20. 解决SQL将varchar值转换为数据类型为int的列时发生语法错误

热门文章

  1. 《C陷阱与缺陷》学习笔记(一)
  2. iOS - 贝塞尔曲线,折线,曲线,波浪线
  3. DataTable行处理
  4. EMC机理------串扰
  5. IE8 &quot;开发人员工具&quot; 无法使用,无法显示
  6. Java学习之路 第四篇 oop和class (面向对象和类)
  7. iOS --生产JSON格式,创建JSON文件,创建文件夹,指定储存
  8. python 基础 8.4 re的 spilt() findall() finditer() 方法
  9. DBUtils使用详解
  10. detached HEAD state