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 数组。

  1. #include<iostream>
  2. #include<cstdio>
  3. #include <cctype>
  4. #include<algorithm>
  5. #include<cstring>
  6. #include<cmath>
  7. #include<string>
  8. #include<cmath>
  9. #include<set>
  10. #include<vector>
  11. #include<stack>
  12. #include<queue>
  13. #include<map>
  14. using namespace std;
  15. #define ll long long
  16. #define mem(a,x) memset(a,x,sizeof(a))
  17. #define se second
  18. #define fi first
  19. const int INF= 0x3f3f3f3f;
  20. const int N=3e5+;
  21.  
  22. int n,m,x,t,c,cnt=;
  23. ll sum=; //查询的答案
  24. int r[N],app[N]; //读过的 和 总的
  25. int num[N]={};
  26. queue<int>q;
  27.  
  28. int main()
  29. {
  30. cin>>n>>m;
  31. while(m--)
  32. {
  33. scanf("%d",&c);
  34. if(c==)
  35. {
  36. scanf("%d",&x);
  37.  
  38. sum++;
  39. q.push(x); //存第几种app
  40. app[x]++;
  41. }
  42. if(c==)
  43. {
  44. scanf("%d",&x);
  45.  
  46. sum-= app[x]-r[x];
  47. r[x]=app[x];
  48. }
  49. if(c==)
  50. {
  51. scanf("%d",&t);
  52.  
  53. t-=cnt; //要减去 已经出队的数量 (题目要求可以阅读重复的信息)
  54. while(!q.empty()&&t>)
  55. {
  56. int f=q.front();
  57. q.pop();
  58. cnt++;//出队数量
  59. num[f]++;
  60. if(num[f]>r[f])
  61. {
  62. sum-=num[f]-r[f];
  63. r[f]=num[f];
  64. }
  65. t--;
  66. }
  67. }
  68. cout<<sum<<endl;
  69. }
  70. }

Codeforces #366 Div. 2 C. Thor (模拟的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. Codeforces #366 (Div. 2) D. Ant Man (贪心)

    https://blog.csdn.net/liangzhaoyang1/article/details/52215276  原博客 原来好像是个dp题,不过我看了别人的博客使用贪心做的 复杂度(n^ ...

  5. 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 ...

  6. Codeforces Beta Round #27 (Codeforces format, Div. 2)

    Codeforces Beta Round #27 (Codeforces format, Div. 2) http://codeforces.com/contest/27 A #include< ...

  7. codeforces #592(Div.2)

    codeforces #592(Div.2) A Pens and Pencils Tomorrow is a difficult day for Polycarp: he has to attend ...

  8. codeforces #578(Div.2)

    codeforces #578(Div.2) A. Hotelier Amugae has a hotel consisting of 1010 rooms. The rooms are number ...

  9. Codeforces #344 Div.2

    Codeforces #344 Div.2 Interview 题目描述:求两个序列的子序列或操作的和的最大值 solution 签到题 时间复杂度:\(O(n^2)\) Print Check 题目 ...

随机推荐

  1. Docker快速入门——Docker-Compose

    一.Docker-Compose简介 1.Docker-Compose简介 Docker-Compose项目是Docker官方的开源项目,负责实现对Docker容器集群的快速编排.Docker-Com ...

  2. Linux配置Docker镜像加速器

    Docker默认镜像为官方镜像,可以配置成国内加速器提高速度 登录阿里云控制台,搜索容器镜像服务获取到镜像加速服务地址 新建配置文件 /etc/docker/daemon.json 输入以下内容 { ...

  3. 用anaconda保证64位和32位的python共存

    conda info # 查看当前工作平台 set CONDA_FORCE_32BIT=1 # 切换到32位 set CONDA_FORCE_32BIT=0 # 切换到64位 conda create ...

  4. openfoam耦合liggghts安装

    本次安装基于新安装的ubuntu18.04LTS桌面版系统,用户名为ubuntu,此前未安装其他软件(进行了系统提醒的更新),安装时间为2019年9月. 安装前需确认需要安装的OpenFOAM版本,C ...

  5. mysql数据库表的查询

    一.            设有一数据库,包括四个表:学生表(Student).课程表(Course).成绩表(Score)以及教师信息表(Teacher).四个表的结构分别如表1-1的表(一)~表( ...

  6. AVIator -- Bypass AV tool

    前提概要 项目地址:https://github.com/Ch0pin/AVIator AV:全名为AntiVirus,意指为防病毒软件 AVIator是一个后门生成器实用程序,它使用加密和注入技术来 ...

  7. 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 ...

  8. go 错误

    错误 Go 程序使用 error 值来表示错误状态. 与 fmt.Stringer 类似,`error` 类型是一个内建接口: type error interface { Error() strin ...

  9. QT-入门:创建项目时遇到工程工具集(Kit)找不到问题

    创建项目遇到了以下提示: Please add a kit in the options or via the maintenance tool of the SDK 解决方法: 在指定的工具链中设置 ...

  10. css文字截断

    通过css将文字进行截断,截断部分使用省略号代替 .impleName{ max-width: 100%; /*最大宽度为当前元素的100%*/ display: inline-block; whit ...