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 题目 ...
随机推荐
- Docker快速入门——Docker-Compose
一.Docker-Compose简介 1.Docker-Compose简介 Docker-Compose项目是Docker官方的开源项目,负责实现对Docker容器集群的快速编排.Docker-Com ...
- Linux配置Docker镜像加速器
Docker默认镜像为官方镜像,可以配置成国内加速器提高速度 登录阿里云控制台,搜索容器镜像服务获取到镜像加速服务地址 新建配置文件 /etc/docker/daemon.json 输入以下内容 { ...
- 用anaconda保证64位和32位的python共存
conda info # 查看当前工作平台 set CONDA_FORCE_32BIT=1 # 切换到32位 set CONDA_FORCE_32BIT=0 # 切换到64位 conda create ...
- openfoam耦合liggghts安装
本次安装基于新安装的ubuntu18.04LTS桌面版系统,用户名为ubuntu,此前未安装其他软件(进行了系统提醒的更新),安装时间为2019年9月. 安装前需确认需要安装的OpenFOAM版本,C ...
- mysql数据库表的查询
一. 设有一数据库,包括四个表:学生表(Student).课程表(Course).成绩表(Score)以及教师信息表(Teacher).四个表的结构分别如表1-1的表(一)~表( ...
- AVIator -- Bypass AV tool
前提概要 项目地址:https://github.com/Ch0pin/AVIator AV:全名为AntiVirus,意指为防病毒软件 AVIator是一个后门生成器实用程序,它使用加密和注入技术来 ...
- English Learning -- 0611--When Burnout Is a Sign You Should Leave Your Job
I like the following article from Harvard Business Review, as I ever experienced burnout at work. Ve ...
- go 错误
错误 Go 程序使用 error 值来表示错误状态. 与 fmt.Stringer 类似,`error` 类型是一个内建接口: type error interface { Error() strin ...
- QT-入门:创建项目时遇到工程工具集(Kit)找不到问题
创建项目遇到了以下提示: Please add a kit in the options or via the maintenance tool of the SDK 解决方法: 在指定的工具链中设置 ...
- css文字截断
通过css将文字进行截断,截断部分使用省略号代替 .impleName{ max-width: 100%; /*最大宽度为当前元素的100%*/ display: inline-block; whit ...