开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. composer install 遇到问题 Problem 1 - phpunit/phpunit 5.7.5 requires php ^5.6 || ^7.0 -> your PHP version (5.5.3 0) does not satisfy that requirement.

    $ composer install Loading composer repositories with package information Updating dependencies (inc ...

  2. openstack私有云布署实践【9.2 Glance镜像管理(办公网环境)】

    首先登录controller1创建glance数据库,并赋于远程和本地访问的权限.      mysql -u root -p   CREATE DATABASE glance; GRANT ALL ...

  3. [UWP小白日记-15]在UWP手机端实时限制Textbox的输入

    说实话重来没想到验证输入是如此的苦逼的一件事情.     网上好多验证都是在输入完成后再验证,我的想法是在输入的时候就限制输入,这样我就不用再写代码来验证了 应为是手机端,所以不用判断其他非法字符,直 ...

  4. HashMap和Hashtable的同和不同

    一.综述 可以直接根据hashcode值判断两个对象是否相等吗?肯定是不可以的,因为不同的对象可能会生成相同的hashcode值.虽然不能根据hashcode值判断两个对象是否相等,但是可以直接根据h ...

  5. asp.net mvc + mysql + ef6

    1.通过NuGet包管理器安装:EntityFramework6.1.3.MySql.Data.Entity6.9.9 2.添加新建项→ADO.NET实体对象模型(命名MyContext)→空Code ...

  6. CentOS单独编译安装PHP gd库扩展

    注意:如果您已经编译安装过GD库,请重新编译安装php不带gd库成功后,执行以下操作 安装libpng wget http://jaist.dl.sourceforge.net/project/lib ...

  7. Js控制iphone端的input/textarea元素失去焦点时隐藏键盘

    原文http://www.it165.net/pro/html/201404/12672.html function objBlur(obj, time){ if(typeof obj != 'str ...

  8. 【IE6的疯狂之十】父级使用padding后子元素绝对定位的BUG

    在前端开发中,经常会用到css的position:absolute来使层浮动,前通过left,top,right等属性来对层进行定位,但ie6对left,top,right等属性的解释和ie7,ie8 ...

  9. ZendStudio9之SVN项目代码提示丢失解决

    前几天转移服务器,SVN 也重建了个,但用着重建的项目发现代码提示丢失了...好郁闷..搞了半天终于找到解决的方法了! 如果你还保留有以前的 SVN 项目本地完整备份,可以直接拷贝以下三个文件到新项目 ...

  10. Python学习笔记——基础篇【第七周】———进程、线程、协程篇(socket基础)

    http://www.cnblogs.com/wupeiqi/articles/5040823.htmlhttp://i.cnblogs.com/EditPosts.aspx?postid=55437 ...