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 题目 ...
随机推荐
- vi 替换命令 以及“找不到模式”解决
转自:https://www.cnblogs.com/zfyouxi/p/5181363.html 在linux vi编辑工具中使用替换命令操作时,会出现明明有匹配查找模式的数据.却报“找不到模式”问 ...
- Warning: Hash history cannot PUSH the same path; a new entry will not be added to the history stack
现象 在用`mobx-react-router`的`this.props.history.push("/")`的时候,浏览器会提示 Warning: Hash history ca ...
- Python unittest框架实现appium登录
import unittest from appium.webdriver import webdriver from ddt import data,ddt,unpack class MyTestC ...
- linux系统 重启盘符错乱问题
linux磁盘重启乱序问题处理 最近到客户那去巡检时,客户提到一个问题,他们的rac在重启的时候,原来的sda1.sdb1.sdc1会对应变成sdd1.sde1.sdf1,由于他们使用的是盘符来绑定裸 ...
- left join 和inner join关联查询区别
inner join 必须两边对应才能查处结果 left join 用主表关联副表,关联不出来依然显示结果
- 史上最浅显易懂的RxJava入门教程
RxJava是一个神奇的框架,用法很简单,但内部实现有点复杂,代码逻辑有点绕.我读源码时,确实有点似懂非懂的感觉.网上关于RxJava源码分析的文章,源码贴了一大堆,代码逻辑绕来绕去的,让人看得云里雾 ...
- 通过docker安装elasticsearch和安装ik分词器插件及安装kibana
前提: 已经安装好docker运行环境: 步骤: 1.安装elasticsearch 6.2.2版本,目前最新版是7.2.0,这里之所以选择6.2.2是因为最新的SpringBoot2.1.6默认支持 ...
- 018 Android Activity界面移入与移出的动画效果
1.平移动画 上一页移入动画 (-屏幕宽度,y)------>(0,y) 上一页移出动画 (0,y)-------------->(屏幕宽度,y) 下一页移入动画 (屏幕宽度,y)---- ...
- 简单实现SpringBoot启动
一.准备: IDEA 使用简单手写导包实现spring boot,未使用idea自带的spring创建方法 可以更加简单理解springboot启动过程 二.开始 1.打开idea创建project ...
- JDBC预编译statement(preparedstatement)和statement的比较、execute与executeUpdate的区别
和 Statement一样,PreparedStatement也是用来执行sql语句的与创建Statement不同的是,需要根据sql语句创建PreparedStatement除此之外,还能够通过设置 ...