题意:给定三个操作,1,是x应用产生一个通知,2,是把所有x的通知读完,3,是把前x个通知读完,问你每次操作后未读的通知。

析:这个题数据有点大,但可以用STL中的队列和set来模拟这个过程用q来标记是哪个应用产生的,用set来记录是第几个通知.

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
using namespace std ; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 3e5 + 5;
const int mod = 1e9 + 7;
const int dr[] = {0, 0, -1, 1};
const int dc[] = {-1, 1, 0, 0};
int n, m;
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
queue<int> q[maxn];
set<int> sets;
set<int> :: iterator it; int main(){
scanf("%d %d", &n, &m);
int ans = 0, cnt = 0, x, y;
for(int i = 0; i < m; ++i){
scanf("%d %d", &x, &y);
if(1 == x){
q[y].push(cnt);
sets.insert(cnt++);
++ans;
}
else if(2 == x){
while(!q[y].empty()){
int u = q[y].front(); q[y].pop();
if(sets.count(u)){
--ans;
sets.erase(u);
}
}
}
else if(3 == x){
for(it = sets.begin(); it != sets.end(); ){
if(*it < y){
sets.erase(it++);
--ans;
}
else break;
}
}
printf("%d\n", ans);
}
return 0;
}

CodeForces 705C Thor (模拟+STL)的更多相关文章

  1. CodeForces 705C Thor

    开30W个vector将数字归类,每一类数字开一个指针P,记录已经阅读到哪一个了,还可以开一个优先队列维护这些指针P. #pragma comment(linker, "/STACK:102 ...

  2. CSP 201612-3 权限查询 【模拟+STL】

    201612-3 试题名称: 权限查询 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 授权 (authorization) 是各类业务系统不可缺少的组成部分,系统用户通过授权 ...

  3. [Codeforces 1246B] Power Products (STL+分解质因数)

    [Codeforces 1246B] Power Products (STL+分解质因数) 题面 给出一个长度为\(n\)的序列\(a_i\)和常数k,求有多少个数对\((i,j)\)满足\(a_i ...

  4. 【模拟】Codeforces 704A & 705C Thor

    题目链接: http://codeforces.com/problemset/problem/704/A http://codeforces.com/problemset/problem/705/C ...

  5. codeforces 705C C. Thor(模拟)

    题目链接: C. Thor time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  6. Codeforces Round #285 (Div. 2) A B C 模拟 stl 拓扑排序

    A. Contest time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  7. Codeforces #366 Div. 2 C. Thor (模拟

    http://codeforces.com/contest/705/problem/C 题目 模拟题 : 设的方法采用一个 r 数组(第几个app已经阅读过的消息的数量),和app数组(第几个app发 ...

  8. Codeforces 704A Thor 队列模拟

    题目大意:托尔有一部手机可执行三种操作 1.x APP产生一个新消息 2.读取x App已产生的所有消息 3.读取前t个产生的消息 问每次操作后未读取的消息的数量 题目思路: 队列模拟,坑点在于竟然卡 ...

  9. Educational Codeforces Round 34 B. The Modcrab【模拟/STL】

    B. The Modcrab time limit per test 1 second memory limit per test 256 megabytes input standard input ...

随机推荐

  1. ASCII码常用值

    大写字母 A~Z 65~90 小写字母a~z 97~122 数字0~9 48~ 57

  2. javac编译过程

    编译器把一种语言规范转化为另一种语言规范的这个过程需要哪些步骤:

  3. 为什么要CGI

    1.微软为什么使用CGI? 微软曾经在不同场合极力推荐它的ASP技术,以取代CGI标准,这对微软当然是有利的,但是对一个网站来说ASP是不是一个明智的选择呢?这是一个值得大家深思熟虑的问题. 因为一旦 ...

  4. context:property-placeholder

    这个在spring中配置文件中是非常常用的. context:property-placeholder大大的方便了我们数据库的配置. 只需要在spring的配置文件里添加一句:<context: ...

  5. operator.itemgetter的用法【转】

    operator.itemgetter函数 operator模块提供的itemgetter函数用于获取对象的哪些维的数据,参数为一些序号(即需要获取的数据在对象中的序号),下面看例子. a = [,, ...

  6. T-SQL备忘(1):表联接

    测试用例表如下: 1.取2个成员表中的交集(A∩B) T-SQL: select Member1.Name,Member1.Age from Member1 join Member2 on Membe ...

  7. jsp防盗链代码

    // 禁止缓存   response.setHeader("Cache-Control", "no-store");   response.setHeader( ...

  8. fastdb中的位图应用

    位图内存管理: 每块内存用一个二进制位表示它的使用状态,如果该块内存被占用,则把对应位图中的对应位置1,如果空闲则置0,原理十分简单.计算机里面处理的位数最少的变量是字节(byte),所以也就是8位做 ...

  9. Android中GridView滚动到底部加载数据终极版

    之前在项目中有一个需求是需要GridView控件,滚动到底部自动加载.但是呢GridView控件并不提供诸如ListView监听滚动到底部的onScrollListener方法,为了实现这样一个效果, ...

  10. WIND2003 安装Zend studio 报错

    在安装zend stutio是系统报错,貌似是签章检验没有通过,去查了一下网上的解决方式多种多样,经过验证后发现以下可以解决我的问题特做记录 机器配置是E2160+4G 异常信息是:File c:\W ...