开30W个vector将数字归类,每一类数字开一个指针P,记录已经阅读到哪一个了,还可以开一个优先队列维护这些指针P。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
inline int read()
{
char c = getchar(); while(!isdigit(c)) c = getchar();
int x = ;
while(isdigit(c)) { x = x * + c - ''; c = getchar(); }
return x;
} const int maxn=+;
vector<int>g[maxn];
int n,q,sz,p[maxn],ans; struct X
{
int num,now,pos,idx;
bool operator < (const X &a) const {
return idx>a.idx;
}
X(int Num,int Now,int Pos,int Idx) {num=Num; now=Now; pos=Pos,idx=Idx;}
};
priority_queue<X>Q; int main()
{
scanf("%d%d",&n,&q);
sz=; ans=; memset(p,-,sizeof p);
for(int i=;i<=q;i++)
{
int t,d; scanf("%d%d",&t,&d);
if(t==)
{
++sz;
if(p[d]==g[d].size()-)
{
Q.push(X(d,p[d],p[d]+,sz));
}g[d].push_back(sz); ans++;
}
else if(t==)
{
ans=ans-(g[d].size()--p[d]);
p[d]=g[d].size()-;
}
else
{
while(!Q.empty()&&Q.top().idx<=d)
{
X h=Q.top(); Q.pop();
if(h.now<p[h.num]) continue;
ans=ans-(h.pos-p[h.num]);
p[h.num]=h.pos;
if(p[h.num]+<g[h.num].size())
Q.push(X(h.num,p[h.num],p[h.num]+,g[h.num][p[h.num]+]));
}
}
printf("%d\n",ans);
}
return ;
}

CodeForces 705C Thor的更多相关文章

  1. CodeForces 705C Thor (模拟+STL)

    题意:给定三个操作,1,是x应用产生一个通知,2,是把所有x的通知读完,3,是把前x个通知读完,问你每次操作后未读的通知. 析:这个题数据有点大,但可以用STL中的队列和set来模拟这个过程用q来标记 ...

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

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

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

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

  4. Codeforces 704A Thor 队列模拟

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

  5. 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 ...

  6. 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 ...

  7. 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 ...

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

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

  9. codeforces 704A (队列模拟) Thor

    题目:这里 题意:n个app,q个操作,当操作数type为1的时候表示y这个app推送了你一条消息,当操作数type为2的时候表示将y这个app已推送的所有消息都读完,当操作数为3的时候 表示将已经推 ...

随机推荐

  1. Python 3

    #对于任意可迭代对象可使用序列拆分操作符*进行拆分 #可用iterable对分片进行赋值等操作(相当于del分片并把iterable插入其中,所以二者长度可以不同) #del取消对象引用与数据项之间的 ...

  2. mysql数据一致性检查及修复

    percona-toolkit-2.2.20-1.noarchmysql 5.6.29-logmaster:192.168.166.129slave:192.168.166.131 一.创建数据库校验 ...

  3. kafka服务安装-SuSE Linux Enterprise Server 11 SP3

    kafka是一款分布式消息发布和订阅的系统,具有高性能和高吞吐率. 更多说明请自行了解,直接进入主题. kakfa 安装之前需要安装jdk,不做更多说明 一.下载kafka  进入下载页面:http: ...

  4. android studio修改项目包名

    公司项目都是用eclipse开发的,但是android studio开发已经是大势所趋了,所以在闲暇之余使用了一下androidstudio,这里对androidstudio更改项目包名做一下总结,因 ...

  5. 在虚拟机上配置linux lab的相关经验

    最近一直在研究怎样在嵌入式开发板上移植linux嵌入式系统,但是不太想花费太多钱购买开发板.然后在网上搜索相关的arm模拟器.有qemu,skyeye,armulator等,在按照网上教程一步一步实践 ...

  6. XTU 1243 2016

    $2016$长城信息杯中国大学生程序设计竞赛中南邀请赛$A$题 循环节. 循环节为$2016$,从数据范围以及题目中的一句话也能间接的体会出应该是有循环节的,并且循环节可能是$2016$. Feel ...

  7. vue跨组件通信的几种方法

    http://www.tuicool.com/articles/jyM32mA 在开发组件的时候,一定会遇到组件的通信,比如点击一个图标出现弹窗和蒙层,这三个分别是不同的组件.管理他们之间的状态就成了 ...

  8. [Q]系统环境改变导致“未注册”的解决方法

    据用户反映设置账户开机密码后显示未注册, 具体表现: 1. 重装试用版,重新获取注册申请码,发现注册申请码跟原来没有发生变化. 2. 重新使用原来的授权文件注册,但打开后显示未注册. 3. 发现“** ...

  9. X11 五子棋

    #include <X11/Xlib.h> #include <stdlib.h> #include <X11/keysym.h> #include <cst ...

  10. Ubuntu14.04浏览器Firefox安装flash播放插件

    sudo apt-get update sudo apt-get install flashplugin-nonfree ================= 类飞秋软件 sudo apt-get in ...