CodeForces 705C Thor
开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的更多相关文章
- CodeForces 705C Thor (模拟+STL)
题意:给定三个操作,1,是x应用产生一个通知,2,是把所有x的通知读完,3,是把前x个通知读完,问你每次操作后未读的通知. 析:这个题数据有点大,但可以用STL中的队列和set来模拟这个过程用q来标记 ...
- 【模拟】Codeforces 704A & 705C Thor
题目链接: http://codeforces.com/problemset/problem/704/A http://codeforces.com/problemset/problem/705/C ...
- codeforces 705C C. Thor(模拟)
题目链接: C. Thor time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- Codeforces 704A Thor 队列模拟
题目大意:托尔有一部手机可执行三种操作 1.x APP产生一个新消息 2.读取x App已产生的所有消息 3.读取前t个产生的消息 问每次操作后未读取的消息的数量 题目思路: 队列模拟,坑点在于竟然卡 ...
- 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 ...
- 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 #366 Div. 2 C. Thor (模拟
http://codeforces.com/contest/705/problem/C 题目 模拟题 : 设的方法采用一个 r 数组(第几个app已经阅读过的消息的数量),和app数组(第几个app发 ...
- codeforces 704A (队列模拟) Thor
题目:这里 题意:n个app,q个操作,当操作数type为1的时候表示y这个app推送了你一条消息,当操作数type为2的时候表示将y这个app已推送的所有消息都读完,当操作数为3的时候 表示将已经推 ...
随机推荐
- Java的常用包
java.lang: 这个包下包含了Java语言的核心类,如String.Math.Sytem和Thread类等,使用这个包无需使用import语句导入,系统会自动导入这个包中的所有类. java. ...
- 用C++实现的八皇后问题
我是一个C++初学者,控制台实现了一个八皇后问题. 代码如下: //"八皇后问题"V1.0 //李国良于2017年1月11日编写完成 #include <iostream&g ...
- Java Web学习笔记--JSP for循环
JSP for循环 <%@ page language="java" contentType="text/html; charset=UTF-8" %&g ...
- 菜鸟互啄:WINFORM如何实现无聚焦框的Button按钮
当我们将一个button按钮设置如下属性时,总有一个聚焦框来困扰着我们 button1.FlatStyle = FlatStyle.Flat; 我们想要的效果是这样的: 但当使用了Tab切换焦点时 发 ...
- Python自动化开发-基础语法
1.编码 计算机只能处理数字,如果要处理文本,就必须先把文本转换为数字才能处理.解决思路:数字与符号建立一对一映射,用不同数字表示不同符号. ASCII(American Standard Code ...
- Python基础之列表
列表的内置方法 1.append() 描述:用于在列表末尾添加新的对象. 示例: msg_list=["aaaa","bbbbb","cccccc&q ...
- SAP HANA 中的决策表(Decision Table)
http://scn.sap.com/community/developer-center/hana/blog/2013/01/11/what-can-you-do-with-decision-tab ...
- unionpay技术服务开放平台
URL: https://open.unionpay.com/ajweb/index USER: jimingsong PWD: qweasd
- 今天学习的裸板驱动之GPIO实验学习心得
GPIO分成很多组今天学习的这个芯片的GPIO有GPA-GPJ个组.具体可在芯片手册中看到. GPIO有很多寄存器,今天学习的这个芯片,他的寄存器分为以下几种类型: (1)端口控制寄存器 (2)端口数 ...
- Web网页数据抓取(C/S)
通过程序自动的读取其它网站网页显示的信息,类似于爬虫程序.比方说我们有一个系统,要提取BaiDu网站上歌曲搜索排名.分析系统在根据得到的数据进行数据分析.为业务提供参考数据. 为了完成以上的需求,我们 ...