开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. [UWP小白日记-12]使用新的Composition API来实现控件的阴影

    前言 看了好久官方的Windows UI Dev Labs示例好久才有点心得,真是头大.(其实是英语幼儿园水平(⊙﹏⊙)b) 真的网上关于这个API的资料可以说几乎没有. 正文 首先用这东西的添加WI ...

  2. CentOS 7安装redis及php扩展

    安装remi源 # wget http://rpms.famillecollet.com/enterprise/remi-release-7.rpm # rpm -Uvh remi-release-7 ...

  3. 石头剪刀布 OpenJudge 1.6.08

    石头剪刀布是常见的猜拳游戏.石头胜剪刀,剪刀胜布,布胜石头.如果两个人出拳一样,则不分胜负. 一天,小A和小B正好在玩石头剪刀布.已知他们的出拳都是有周期性规律的,比如:"石头-布-石头-剪 ...

  4. Activiti工作流入门

    Activiti简介 Activiti是一个开源的工作流引擎,它实现了BPMN 2.0规范,可以发布设计好的流程定义,并通过api进行流程调度. Activiti 作为一个遵从 Apache 许可的工 ...

  5. Linux升级glibc

    参考http://www.linuxidc.com/Linux/2015-04/116472.htm via 红孩儿你好 一.简介 glibc是gnu发布的libc库,即c运行库.glibc是linu ...

  6. Jedis实现发布订阅功能

    Redis为我们提供了publish/subscribe(发布/订阅)功能.我们可以对某个channel(频道)进行subscribe(订阅),当有人在这个channel上publish(发布)消息时 ...

  7. 关于ajax的短轮询问题

    利用前台的ajax不断向后台服务器请求,后台服务器不断查看数据库里的信息是否变化.若变化将信息返回前台,并执行一些操作 前台ajax代码 注意要加上cache这一项,如果是post请求的化,可以免了. ...

  8. c#如何使两个方法并行运行

    static void Main(string[] args)        {            Parallel.Invoke(Foo, Bar);        } static void ...

  9. ios开发的系统兼容性问题解决

    对于系统中过时的方法或者是为了向下兼容兼容不同的版本使用最新的方法都要判断当前的系统版本号,在进行方法的调用 1.系统方法过时的注释 ````objc - (void)imagePickerContr ...

  10. E - Cup 2(dfs)

    E - Cup 2 Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Submit Stat ...