题目链接:

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;
}

  

codeforces 705C C. Thor(模拟)的更多相关文章

  1. CodeForces 705C Thor (模拟+STL)

    题意:给定三个操作,1,是x应用产生一个通知,2,是把所有x的通知读完,3,是把前x个通知读完,问你每次操作后未读的通知. 析:这个题数据有点大,但可以用STL中的队列和set来模拟这个过程用q来标记 ...

  2. Codeforces #366 Div. 2 C. Thor (模拟

    http://codeforces.com/contest/705/problem/C 题目 模拟题 : 设的方法采用一个 r 数组(第几个app已经阅读过的消息的数量),和app数组(第几个app发 ...

  3. CodeForces 705C Thor

    开30W个vector将数字归类,每一类数字开一个指针P,记录已经阅读到哪一个了,还可以开一个优先队列维护这些指针P. #pragma comment(linker, "/STACK:102 ...

  4. Codeforces 738D. Sea Battle 模拟

    D. Sea Battle time limit per test: 1 second memory limit per test :256 megabytes input: standard inp ...

  5. Codeforces 626A Robot Sequence(模拟)

    A. Robot Sequence time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...

  6. CodeForces - 589D(暴力+模拟)

    题目链接:http://codeforces.com/problemset/problem/589/D 题目大意:给出n个人行走的开始时刻,开始时间和结束时间,求每个人分别能跟多少人相遇打招呼(每两人 ...

  7. Codeforces 767B. The Queue 模拟题

    B. The Queue time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...

  8. CF #366 DIV2 C. Thor 模拟 queue/stack降低复杂度

    C. Thor time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...

  9. Vasya And The Mushrooms CodeForces - 1016C (前缀和模拟)

    大意: 给定2*n的矩阵, 每个格子有权值, 走到一个格子的贡献为之前走的步数*权值, 每个格子只能走一次, 求走完所有格子最大贡献. 沙茶模拟打了一个小时总算打出来了 #include <io ...

随机推荐

  1. oled屏幕

    oled作为一种新型的有机显示屏,越来越现实出其重要性,它不但超薄可弯折并且可视视角较宽.处在不论什么角度看屏幕都不会造成图像的失真. 且它有三中原色:绿.红,蓝. 我近期在学安在智能车上的oled ...

  2. Robot Framework ---Selenium API

    一.浏览器驱动 通过不同的浏览器执行脚本. Open Browser Htpp://www.xxx.com chrome 浏览器对应的关键字: firefox FireFox ff internete ...

  3. yosemite开启HAXM硬件加速执行安卓虚拟机

    android sdk安装HAXM发现不能正常执行 $ kextstat | grep intel 发现无进程执行 $ sudo kextload –b com.intel.kext.intelhax ...

  4. Splash动画启动app时空白屏

    相信大多数人一开始都会对启动app的时候出现先白瓶或者黑屏然后才进入第一个界面,例如:SplashActivity.那这是什么原因造成的呢? <style name="Splash_T ...

  5. 想全面理解JWT?一文足矣!

    有篇关于JWT的文章,叫"JWT: The Complete Guide to JSON Web Tokens",写得全面细致.为了自己能更清晰理解并惠及更多人,我把它大致翻译了过 ...

  6. Multicast注册中心

    1 2 3 4 提供方启动时广播自己的地址. 消费方启动时广播订阅请求. 提供方收到订阅请求时,单播自己的地址给订阅者,如果设置了unicast=false,则广播给订阅者. 消费方收到提供方地址时, ...

  7. Spark源码分析之二:Job的调度模型与运行反馈

    在<Spark源码分析之Job提交运行总流程概述>一文中,我们提到了,Job提交与运行的第一阶段Stage划分与提交,可以分为三个阶段: 1.Job的调度模型与运行反馈: 2.Stage划 ...

  8. nginx教程1:location 匹配规则

    worker_process # 表示工作进程的数量,一般设置为cpu的核数 worker_connections # 表示每个工作进程的最大连接数 server{} # 块定义了虚拟主机 liste ...

  9. DIV+CSS一些小小的技巧

    DIV+CSS网页布局技巧实例1:设置网页整体居中的代码 以前用表格布局时设置网页居中非常方便,把表格对齐方式设置为居中就行了,就这么简单,现在呢,用DIV+CSS样式表控制,好像不是那么容易了,其实 ...

  10. 九度OJ 1013:开门人和关门人 (排序)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:5052 解决:2563 题目描述:     每天第一个到机房的人要把门打开,最后一个离开的人要把门关好.现有一堆杂乱的机房签到.签离记录,请 ...