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 ...
随机推荐
- php 倒计时程序
<html> <head> <meta http-equiv="Content-Type" content="text/html; ch ...
- nginx绑定多个域名
nginx绑定多个域名涉及到的技术为url rewrite,可以先了解下知识背景再过来学习. 这里以域名:www.sample.com为例 1.在/usr/local/nginx/conf文件夹中创建 ...
- nginx下的rewrite
一.正则表达式匹配,其中: * ~ 为区分大小写匹配 * ~* 为不区分大小写匹配 * !~和!~*分别为区分大小写不匹配及不区分大小写不匹配 二.文件及目录匹配,其中: * -f和!-f用来判断是否 ...
- click 绑定(二)带参数的click 事件绑定
注1:传参数给你的click 句柄 最简单的办法是传一个function包装的匿名函数: <button data-bind="click: function() { viewMode ...
- Linux驱动设计—— 内外存访问
本节对内外存访问做详细的介绍. 驱动程序加载成功的一个关键因素,就是内核能够为驱动程序分配足够的内存空间.这些空间一部分用于驱动程序必要的数据结构,另一部分用于数据的交换.同时,内核也应该具有访问外部 ...
- 强化学习之 免模型学习(model-free based learning)
强化学习之 免模型学习(model-free based learning) ------ 蒙特卡罗强化学习 与 时序查分学习 ------ 部分节选自周志华老师的教材<机器学习> 由于现 ...
- PowerDesigner的图形工具栏被我关了 怎么才能恢复?就是那个快捷工具栏 图形那个里面有什么放大镜 表 视图什么的
PowerDesigner的图形工具栏被我关了 怎么才能恢复?就是那个快捷工具栏 图形那个里面有什么放大镜 表 视图什么的 工具-->自定义工具栏-->palette选中
- how-to-install-hyper-v-on-a-virtual-machine-in-hyper-v.aspx
BEFORE STARTING IT IS IMPORTANT TO KNOW THAT THIS ENVIRONMENT IS NOT SUPPORTED BY MICROSOFT. USE IT ...
- 【转】 Ucenter同步登录原理解析
应用中调用函数us_user_synlogin并输出 echo uc_user_synlogin($uid); 解析: 1. 该函数位于client.PHP中 2. 作用实质上是调用ucenter u ...
- python ImportError: No module named 的问题
https://my.oschina.net/leejun2005/blog/109679 python中,每个py文件被称之为模块,每个具有__init__.py文件的目录被称为包.只要模块或者包所 ...