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 (模拟的更多相关文章

  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. 向多个git仓库提交

    查看所有远程仓库 为了不用每次输密码,可以先配置ssh key 查看 添加远程仓库 git remote add origin1 git@other:YYYYYYYYYY/AA.git 向新的代码仓库 ...

  2. Selenium(二十):expected_conditions判断页面元素

    1. 判断元素(expected_conditons) 作为一个刚刚转到python开发的小朋友,在开发前只将前辈们封装的方法看了一遍,学了一边selenium基础.看到封装的方法有什么判断元素是否存 ...

  3. velocity 自定义工具类接入

    网上的教程几乎都是同一篇: velocity 自定义工具类 - eggtk - CSDN 博客 但是教程有不完善的地方,我就补充一下. 补充: 引入的jar包和版本要一致.我们项目中因为没有定义确切版 ...

  4. Ehcache配置文件ehcache.xml

    <?xml version="1.0" encoding="UTF-8"?> <ehcache xmlns:xsi="http:// ...

  5. LeetCode 20. 有效的括号(Valid Parentheses)

    20. 有效的括号 20. Valid Parentheses 题目描述 给定一个只包括 '(',')','{','}','[',']' 的字符串,判断字符串是否有效. 有效字符串需满足: 左括号必须 ...

  6. 八皇后问题——列出所有的解,可推至N皇后

    <数据结构>--邓俊辉版本 读书笔记 今天学习了回溯法,有两道习题,一道N皇后,一道迷宫寻径.今天,先解决N皇后问题.由于笔者 擅长java,所以用java重现了八皇后问题. 注意是jav ...

  7. 02 Python 函数的一些小笔记

    函数的返回值 1.使用return可以返回多个值,如:return a,b 返回的数据类型是元组型2.接收返回的元组可以如:c,d=demo() (假设demo()返回a,b元组),需要注意的是,接收 ...

  8. Android--圆角背景style

    <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http: ...

  9. IDEA好用插件推荐

    Maven Helper:排查maven依赖冲突神器,强力推荐! Alibaba Java Coding Guidelines:阿里巴巴编程规范 CamelCase:驼峰命名工具,SHIFT + AL ...

  10. css文字截断

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