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添加的顺序,按顺序读t条信息,注意这t条信息可能有的已经读过。如果读过也算前t条,会再读一遍。
最后输出每次操作有多少信息没读。
题解:
一看题,要30W,那肯定不可以n^2了,想一想,3种操作,一个vector够用吗,应该不够,所以再加个set,就差不多了。那么思路就是这样的:
首先要有个计数器cnt,从1开始,他的作用是为了第3个操作的,这样就可以知道那些是前x个了,就不会多删掉。之后vei[x]放cnt,如果2操作,就先根据vei[x][0]~vei[x][vei.size()]把set里的删去,之后在vei[x].claer()就好了。
代码:
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300000 + 9 ;
vector<int>vei[MAXN];
set<int>sei;
int n, q, a, x, cnt = 1;
int main()
{
cin >> n >> q;
for(int i = 0; i < q; i++)
{
cin >> a >> x;
if(a == 1)
{
vei[x].push_back(cnt);
sei.insert(cnt++);
}
else if(a == 2)
{
for(int j = 0; j < vei[x].size(); j++)
{
sei.erase(vei[x][j]);
}
vei[x].clear();
}
else
{
while(1)
{
if(*sei.begin() > x || sei.empty()) break;
else sei.erase(*sei.begin());
}
}
cout << sei.size() << endl;
}
return 0;
}
Codeforces Round #366 (Div. 2) C Thor(模拟+2种stl)的更多相关文章
- 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)_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 ...
随机推荐
- PPT图片快速编辑技巧
修改*.ppt或*.pptx的后缀名为zip 例如:demo.pptx修改为demo.zip 修改为, 使用压缩软件打开此压缩包, 一般图片资源都会存放在ppt/media下 找到你所要修改的图片,然 ...
- 安卓应用运营知识:VersionCode和VersionName
本文转载于:http://blog.sina.com.cn/s/blog_580a227a0101bdzb.html 小米应用商店运营了大概半年了,过程中有喜有泪,我们在运营过程中,发现有的运营和商务 ...
- “访问 IIS 元数据库失败”错误的解决方法
1.依次点击“开始”-“运行”. 2.在“运行”栏内输入 “C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -i ...
- gprof使用介绍
gprof 1.1 简介 gprof实际上只是一个用于读取profile结果文件的工具.gprof采用混合方法来收集程序的统计信息,他使用检测方法,在编译过程中在函数入口处插入计数器用于收集 ...
- 【Unity3D插件】在Unity中读写文件数据:LitJSON快速教程
作者:王选易,出处:http://www.cnblogs.com/neverdie/ 欢迎转载,也请保留这段声明.如果你喜欢这篇文章,请点[推荐].谢谢! 介绍 JSON是一个简单的,但功能强大的序列 ...
- python数据库连接池
python数据库连接池 import psycopg2 import psycopg2.pool dbpool=psycopg2.pool.PersistentConnectionPool(1,1, ...
- C++多继承
1.继承的三种方式: 公有继承(public),私有继承(private),保护继承(protected)三种继承方式的说明,如下表所示: 特征 公有继承 保护继承 私有继承 公有成员变成 派生类的公 ...
- easyUI之window
window组件是一个可拖动.浮动的面板,用于显示信息.内容可用 href或ajax获取. window是一个显示窗口,同时也可以显示layout的功能(也就是创建复合的组合窗口),如 <div ...
- codevs-1447取出整数的一部分
说实在的,这个题目真不想写了…… 1447 取出整数的一部分 题目描述 Description 假如有一个整数(int):145678,现在我做截取该数一部份的操作,如输入4,返回前4位即1456;如 ...
- C#文本文件(.txt)读写
目录 前言 读取txt文件 写入txt文件 前言 计算机在最初只支持ASCII编码,但是后来为了支持其他语言中的字符(比如汉字)以及一些特殊字符(比如€),就引入了Unicode字符集.基于Unico ...