Codeforces Round #366 (Div. 2) C. Thor (模拟)
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. Iftypei = 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).
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
In the first sample:
- Application 3 generates a notification (there is 1 unread notification).
- Application 1 generates a notification (there are 2 unread notifications).
- Application 2 generates a notification (there are 3 unread notifications).
- Thor reads the notification generated by application 3, there are 2 unread notifications left.
In the second sample test:
- Application 2 generates a notification (there is 1 unread notification).
- Application 4 generates a notification (there are 2 unread notifications).
- Application 2 generates a notification (there are 3 unread notifications).
- Thor reads first three notifications and since there are only three of them so far, there will be no unread notification left.
- Application 3 generates a notification (there is 1 unread notification).
- Application 3 generates a notification (there are 2 unread notifications).
自己做的时候没想到用队列, 我只想到了从3到2的影响的解决方案,想不出来从2的到3的解决方案。QAQ
本题用队列做。
对于1,用sum队列记录每个进入的编号 cnt++,同时每个应用也要开的队列,把此编号加入到每个应用的队列中。
对于2,开一个used数组,如果used[vis[y].front()]=0,那么此条消息没看过,更新used值,ans++, pop。
对于3,从总的队列sum出,直到队列为空或者当前编号小于y。
结果cnt-ans.
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
using namespace std;
const int maxn = 3e5+;
queue<int> sum,vis[maxn];
int used[maxn];
int main()
{
int n,q;
cin>>n>>q;
int ans = ;
int cnt = ;
int x,y;
for(int i=;i<=q;i++)
{
scanf("%d %d",&x,&y);
if(x==)
{
cnt++;
vis[y].push(cnt);
sum.push(cnt);
}
else if(x==)
{
while(!vis[y].empty())
{
if(!used[vis[y].front()])
{
used[vis[y].front()] = ;
ans++;
}
vis[y].pop();
}
}
else
{
while(!sum.empty()&&sum.front()<=y)
{ if(!used[sum.front()])
{
used[sum.front()] = ;
ans++;
}
sum.pop();
}
}
printf("%d\n",cnt-ans);
}
return ;
}
Codeforces Round #366 (Div. 2) C. Thor (模拟)的更多相关文章
- Codeforces Round #366 (Div. 2) C Thor(模拟+2种stl)
Thor 题意: 第一行n和q,n表示某手机有n个app,q表示下面有q个操作. 操作类型1:app x增加一条未读信息. 操作类型2:一次把app x的未读信息全部读完. 操作类型3:按照操作类型1 ...
- Codeforces Round #366 (Div. 2)_C. Thor
C. Thor time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces #366 Div. 2 C. Thor (模拟
http://codeforces.com/contest/705/problem/C 题目 模拟题 : 设的方法采用一个 r 数组(第几个app已经阅读过的消息的数量),和app数组(第几个app发 ...
- Codeforces Round #366 (Div. 2) C 模拟queue
C. Thor time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...
- Codeforces Round #366 (Div. 2) A , B , C 模拟 , 思路 ,queue
A. Hulk time limit per test 1 second memory limit per test 256 megabytes input standard input output ...
- Codeforces Round #366 Div.2[11110]
这次出的题貌似有点难啊,Div.1的Standing是这样的,可以看到这位全站排名前10的W4大神也只过了AB两道题. A:http://codeforces.com/contest/705/prob ...
- Codeforces Round #301 (Div. 2)(A,【模拟】B,【贪心构造】C,【DFS】)
A. Combination Lock time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...
- Codeforces Round #345 (Div. 2)【A.模拟,B,暴力,C,STL,容斥原理】
A. Joysticks time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...
随机推荐
- mysql创建计算列
mysql> create table t(id int auto_increment not null,c1 int,c2 int,c3 int as (c1+c2),primary key( ...
- json 与entity/list/map的转换
一 json -> entity User.java package com.xxx.hotel.train.json.json2entity; import java.io.Serializ ...
- ORACLE小工具:存储过程清空所有表或使所有触发器失效
清空所有表: CREATE OR REPLACE PROCEDURE CLEAN_TABLES as v_tablename varchar2(256); cursor cur_tablename i ...
- 十七、oracle 权限
一.介绍这一部分我们主要看看oracle中如何管理权限和角色,权限和角色的区别在哪里.当刚刚建立用户时,用户没有任何权限,也不能执行任何操作.如果要执行某种特定的数据库操作,则必须为其授予系统的权限: ...
- jquery 1.9版本后不在支持browser 方法的解决方案
今天对jquery 进行升级,导致项目出错,原来在1.9版本之后 jquery 不支持browser 方法了. 官方建议的又不好用,所以我所jquery 原来的代码摘除来,又扩展回去. //解决jq ...
- android异步Http框架
首先在GitHub上下载异步Http框架代码以及相关文档: 将jar包放入lib包中即可: 接下来分别实现get.post.文件上传功能实现: 代码实现如下: AsyncHttpClient clie ...
- 《JS权威指南学习总结--4.9.3in和instanceof运算符》
内容要点: 一.in运算符 in运算符希望它的左操作数是一个字符串或可以转换为字符串,希望它的右操作数是一个对象.如果右侧的对象拥有一个名为左操作数数值的属性名,那么表达式返回true. 例如: va ...
- 更改web project 访问项目名称
1.新建web project 2.右键该项目名称------properties 3.访问该项目的URL http://localhost:8806/ssm/.......... 相比书写整个项目名 ...
- FUSE
FUSE is particularly useful for writing [ vritual ] file system. Unlike traditional filesystem that ...
- IE10以下的placeholder不兼容问题
$(function(){ if(!placeholderSupport()){ // 判断浏览器是否支持 placeholder $('[placeholder]').focus(fun ...