Codeforces #366 Div. 2 C. Thor (模拟
http://codeforces.com/contest/705/problem/C 题目
模拟题 : 设的方法采用一个 r 数组(第几个app已经阅读过的消息的数量),和app数组(第几个app发出的消息的总数),加上一个 q 队列。
思路:
查询==1的时候,入队(记录顺序), sum++ (sum 为全部的剩余 没阅读的数量)
查询==2的时候,针对一个app,sum -(这个app发出的消息的总数 - 这个app已经阅读过的消息的数量),然后用 app数组 更新 r 数组,表示这个app的全部的消息都已经被阅读过了。
查询==3的时候,采用 q.front 和 q.pop() 的方法一个一个出队,t 为要阅读 队列前面 t 个数量的消息,但是因为有出队的过程,所以出队的数量要用cnt记录,t= t - cnt 。 按顺序出队,当 某一个app消息的数量 > 这个app已经读过的消息的数量(即这个app存在还没被读过的消息),sum就减去 “没被读过的消息的数量”,更新 r 数组。
#include<iostream>
#include<cstdio>
#include <cctype>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<string>
#include<cmath>
#include<set>
#include<vector>
#include<stack>
#include<queue>
#include<map>
using namespace std;
#define ll long long
#define mem(a,x) memset(a,x,sizeof(a))
#define se second
#define fi first
const int INF= 0x3f3f3f3f;
const int N=3e5+; int n,m,x,t,c,cnt=;
ll sum=; //查询的答案
int r[N],app[N]; //读过的 和 总的
int num[N]={};
queue<int>q; int main()
{
cin>>n>>m;
while(m--)
{
scanf("%d",&c);
if(c==)
{
scanf("%d",&x); sum++;
q.push(x); //存第几种app
app[x]++;
}
if(c==)
{
scanf("%d",&x); sum-= app[x]-r[x];
r[x]=app[x];
}
if(c==)
{
scanf("%d",&t); t-=cnt; //要减去 已经出队的数量 (题目要求可以阅读重复的信息)
while(!q.empty()&&t>)
{
int f=q.front();
q.pop();
cnt++;//出队数量
num[f]++;
if(num[f]>r[f])
{
sum-=num[f]-r[f];
r[f]=num[f];
}
t--;
}
}
cout<<sum<<endl;
}
}
Codeforces #366 Div. 2 C. Thor (模拟的更多相关文章
- 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) D. Ant Man (贪心)
https://blog.csdn.net/liangzhaoyang1/article/details/52215276 原博客 原来好像是个dp题,不过我看了别人的博客使用贪心做的 复杂度(n^ ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Beta Round #27 (Codeforces format, Div. 2)
Codeforces Beta Round #27 (Codeforces format, Div. 2) http://codeforces.com/contest/27 A #include< ...
- codeforces #592(Div.2)
codeforces #592(Div.2) A Pens and Pencils Tomorrow is a difficult day for Polycarp: he has to attend ...
- codeforces #578(Div.2)
codeforces #578(Div.2) A. Hotelier Amugae has a hotel consisting of 1010 rooms. The rooms are number ...
- Codeforces #344 Div.2
Codeforces #344 Div.2 Interview 题目描述:求两个序列的子序列或操作的和的最大值 solution 签到题 时间复杂度:\(O(n^2)\) Print Check 题目 ...
随机推荐
- 如何解决mac brew遇到无法下载的依赖?
使用brew安装软件时,需要下载依赖包,但是如果依赖包特别大的时候,就很容易失败:brew本身不支持断点续传:但是可以使用wget -c的方式断点续传的下载依赖:下载完如何给brew安装使用呢?参考: ...
- 实验1 C 语言开发环境使用和数据类型、运算符、表达式
# include <stdio.h> int main() { int x; printf("x:\n"); scanf("%d",&x) ...
- 2019.10.28 IDEA入门指南(很多人问补充一篇)
Idea快速入门指南 1.安装 1.1.安装 我们使用的是最新的2017.3.4版本: 双击打开, 选择一个目录,最好不要中文和空格: 然后选择桌面快捷方式,请选择64位: 然后选择安装: 开始安装: ...
- LeetCode 637. 二叉树的层平均值(Average of Levels in Binary Tree)
637. 二叉树的层平均值 637. Average of Levels in Binary Tree LeetCode637. Average of Levels in Binary Tree 题目 ...
- [转帖]AMD三代锐龙线程撕裂者命名曝光:24核心3960X
AMD三代锐龙线程撕裂者命名曝光:24核心3960X https://www.cnbeta.com/articles/tech/900271.htm 一直搞不懂TDP啥意思 可能会高于TDP的功率.. ...
- stm32之中断响应优先级
1)中断响应分为:自然优先级.抢占优先级.响应优先级. 2)抢占优先级和响应优先级,其实是一个中断所包含的两个优先级,其中前者是抢占优先级之间的级别划分,后者是相同抢占优先级的优先级别的划分. 中断A ...
- 如何做好PPT
为什么要做ppt 全图型PPT,一张大图做背景,少量的文字---PPT大师Garr Renolds极力推崇的风格 半图型PPT PTT是为了和你的"客户"有效的沟通 好的PPT G ...
- dotnetcore 与 hbase 之三——c# for hbase 客户端的使用
说明 在上一篇文章dotnetcore 与 hbase 之二--thrift 客户端的制作中已经可以找到 c# hbase 客户端的使用方法了,为什么这里单独列出一篇文章来讲述呢?最简单的理由就是,本 ...
- hdu 2555
Problem Description 杭州师范大学第29届田径运动会圆满的闭幕了,本届运动会是我校规模最大,参赛人数最多的一次运动会.在两天半时间里,由学生.教工组成的61支代表队共2664名运动员 ...
- 线程二(Monitor)
Monitor 类的命名空间是 System.Threading,它的用法和 lock 本质是一样的. 使用 Monitor 类锁定资源的代码如下. Monitor.Enter(object); tr ...