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 题目 ...
随机推荐
- Git出现There is no tracking information for the current branch提示的解决办法
参考:https://blog.csdn.net/sinat_36246371/article/details/79738782 在执行git pull的时候,提示当前branch没有跟踪信息: Th ...
- python 爬虫实例(二)
环境: OS:Window10 python:3.7 描述 打开下面的网址,之后抓取其中的图片 https://music.163.com/#/artist/album?id=101988&l ...
- go创建模块化项目
比如我要创建一个xxx-system,里面可能有多个子模块,步骤如下: 1.mkdir xxx-system 2.cd xxx-system 3.在xxx-system目录下创建一系列的service ...
- 线性表——顺序表的实现与讲解(C++描述)
线性表 引言 新生安排体检,为了 便管理与统一数据,学校特地规定了排队的方式,即按照学号排队,谁在前谁在后,这都是规定好的,所以谁在谁不在,都是非常方便统计的,同学们就像被一条线(学号)联系起来了,这 ...
- 用pytorch1.0快速搭建简单的神经网络
用pytorch1.0搭建简单的神经网络 import torch import torch.nn.functional as F # 包含激励函数 # 建立神经网络 # 先定义所有的层属性(__in ...
- 虚拟机性能监控与故障处理工具(深入理解java虚拟机三)
JDK自带的工具可以方便的帮助我们处理一些问题,包括查看JVM参数,分析内存变化,查看内存区域,查看线程等信息. 我们熟悉的有java.exe,javac.exe,javap.exe(偶尔用),jps ...
- SQL语言(一)
数据定义语言:简称DDL(Data Definition Language) create database 数据库名 character set 'utf-8'; drop database 数据库 ...
- Linux基础-15-samba服务
1. samba的功能: samba是一个网络服务器,用于Linux和Windows之间共享文件. 2. samba服务的启动.停止.重启 service smb start|stop|restart ...
- python学习-56 贪吃蛇🐍
import random, pygame, sys from pygame.locals import * FPS = 15 WINDOWWIDTH = 640 WINDOWHEIGHT = 480 ...
- WUSTOJ 1335: Similar Word(Java)
题目链接:1335: Similar Word Description It was a crummy day for Lur. He failed to pass to the CET-6 (Col ...