codeforces 705C 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 题意: 现在给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(模拟)的更多相关文章
- CodeForces 705C Thor (模拟+STL)
题意:给定三个操作,1,是x应用产生一个通知,2,是把所有x的通知读完,3,是把前x个通知读完,问你每次操作后未读的通知. 析:这个题数据有点大,但可以用STL中的队列和set来模拟这个过程用q来标记 ...
- Codeforces #366 Div. 2 C. Thor (模拟
http://codeforces.com/contest/705/problem/C 题目 模拟题 : 设的方法采用一个 r 数组(第几个app已经阅读过的消息的数量),和app数组(第几个app发 ...
- CodeForces 705C Thor
开30W个vector将数字归类,每一类数字开一个指针P,记录已经阅读到哪一个了,还可以开一个优先队列维护这些指针P. #pragma comment(linker, "/STACK:102 ...
- Codeforces 738D. Sea Battle 模拟
D. Sea Battle time limit per test: 1 second memory limit per test :256 megabytes input: standard inp ...
- Codeforces 626A Robot Sequence(模拟)
A. Robot Sequence time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...
- CodeForces - 589D(暴力+模拟)
题目链接:http://codeforces.com/problemset/problem/589/D 题目大意:给出n个人行走的开始时刻,开始时间和结束时间,求每个人分别能跟多少人相遇打招呼(每两人 ...
- Codeforces 767B. The Queue 模拟题
B. The Queue time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...
- 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 ...
- Vasya And The Mushrooms CodeForces - 1016C (前缀和模拟)
大意: 给定2*n的矩阵, 每个格子有权值, 走到一个格子的贡献为之前走的步数*权值, 每个格子只能走一次, 求走完所有格子最大贡献. 沙茶模拟打了一个小时总算打出来了 #include <io ...
随机推荐
- jquery方法
$.inArray(被判断的量,ArrayName); 如果存在返回索引值,如果不存在返回-1 $.unique() 数组去重 根据去重前后的长度,判断是否有重复 $.each(被遍历的数组,f ...
- 线性表的链式实现(C++)
相关内容: 线性表的顺序实现 链式实现(C语言) (推荐在GitHub上查看,下面代码只是最初实现,后续如果有修改,由于太麻烦,不会再更改下文,仅仅更新Github上的代码文件) 结点以及链表类的定义 ...
- 如何使用CocoaPods安装使用及配置私有库以及管理依赖库 【原创】
CocoaPods是什么 在iOS开发中势必会用到一些第三方依赖库,比如大家都熟悉的ASIHttpRequest.AFNetworking.JSONKit等.使用这些第三方类库能极大的方便项目的开发, ...
- JavaScript toString() 方法
注意:在JavaScript中,数字后面的"."操作符是的意义是不确定.因为它既可能是一个浮点数的标志,又可能是取一个对象的属性的运算符.但是JavaScript的解释器把他当做了 ...
- 转载 ----Android学习笔记 - 蓝牙篇 (Bluetooth)
1.什么是蓝牙 Bluetooth是目前使用的最广泛的无线通讯协议之一 主要针对短距离设备通讯(10米) 常用于连接耳机.鼠标和移动通讯设备等 2.发现周围蓝牙设备 BluetoothAd ...
- php部分--题目:投票 重点:两个div套用,显示百分比;
1.建立两个表格:要显示百分比的话,就要在选项表中加上一列标记number 2.链接数据库,并对题目和选项进行显示 <?php $db=new MySQLi("localhost&qu ...
- COGS1752. [BOI2007]摩基亚Mokia
1752. [BOI2007]摩基亚Mokia ★★☆ 输入文件:mokia.in 输出文件:mokia.out 简单对比时间限制:5 s 内存限制:128 MB [题目描述] 摩尔瓦 ...
- 【BZOJ4264】小C找朋友 随机化
[BZOJ4264]小C找朋友 Description 幼儿园里有N个小C,两个小C之间可能是朋友也可能不是.所有小C之间的朋友关系构成了一个无向图,这个无向图中有M条边. 园长ATM发现对于两个(不 ...
- DSP/BIOS使用之初窥门径——滴答时钟及烧写Flash
操作平台和环境 DSP型号:TMS320C6713 仿真器:XDS510PLUS Flash型号:AM29LV800BT或AM29LV800BT都试过(一般接口一样,区别不大) RAM型号:MT48L ...
- CMMI过程改进反例
近期一直在看CMMI的资料,越看认为越有意思.今天看到过程改进的时候,突然想起来之前所在的公司发生的过程改进相关的事儿来. 公司通过CMMI3级认证之后.PMO部门经理(公司还有质量管理部门经理 ...