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 ...
随机推荐
- HDU 1312 Red and Black --- 入门搜索 BFS解法
HDU 1312 题目大意: 一个地图里面有三种元素,分别为"@",".","#",其中@为人的起始位置,"#"可以想象 ...
- linux 下查看机器是cpu是几核的(转)
几个cpu more /proc/cpuinfo |grep "physical id"|uniq|wc -l 每个cpu是几核(假设cpu配置相同) more /proc/cpu ...
- POJ2125 Destroying The Graph (最小点权覆盖集)(网络流最小割)
Destroying The Graph Time Limit: 2000MS Memo ...
- HDU-5536 Chip Factory (字典树)
题目大意:给n个数,编号为1~n,取三个编号不同的数,使表达式(a+b)^c的值最大. 题目分析:将这n个数按二进制位建立一棵trie.枚举i.j的和,查询亦或最大值,但在查询之前要把i.j在trie ...
- 论文笔记之:Heterogeneous Image Features Integration via Multi-Modal Semi-Supervised Learning Model
Heterogeneous Image Features Integration via Multi-Modal Semi-Supervised Learning Model ICCV 2013 本文 ...
- Qt消息机制和事件(一)
一,事件 事件(event)是由系统或者 Qt 本身在不同的时刻发出的.当用户按下鼠标.敲下键盘,或者是窗口需要重新绘制的时候,都会发出一个相应的事件.一些事件在对用户操作做出响应时发出,如键盘事件等 ...
- Android开源项目第一篇——个性化控件(View)篇
本文为那些不错的Android开源项目第一篇——个性化控件(View)篇,主要介绍Android上那些不错个性化的View,包括ListView.ActionBar.Menu.ViewPager.Ga ...
- 掌握 Ajax,第 2 部分: 使用 JavaScript 和 Ajax 发出异步请求
转http://www.ibm.com/developerworks/cn/xml/wa-ajaxintro2/ 掌握 Ajax,第 2 部分: 使用 JavaScript 和 Ajax 发出异步请求 ...
- python部分模块的安装
scrapy http://www.cnblogs.com/txw1958/archive/2012/07/12/scrapy_installation_introduce.html pyHook - ...
- 【转】javascript弹出固定大小的窗口页面
来源:http://weicfprince.blog.163.com/blog/static/8441066920081010113231969/ 现在我们想弹出一个WEB窗体,让其处于屏幕的中间位置 ...