Codeforces Round #590 (Div. 3) B2. Social Network (hard version)
链接:
https://codeforces.com/contest/1234/problem/B2
题意:
The only difference between easy and hard versions are constraints on n and k.
You are messaging in one of the popular social networks via your smartphone. Your smartphone can show at most k most recent conversations with your friends. Initially, the screen is empty (i.e. the number of displayed conversations equals 0).
Each conversation is between you and some of your friends. There is at most one conversation with any of your friends. So each conversation is uniquely defined by your friend.
You (suddenly!) have the ability to see the future. You know that during the day you will receive n messages, the i-th message will be received from the friend with ID idi (1≤idi≤109).
If you receive a message from idi in the conversation which is currently displayed on the smartphone then nothing happens: the conversations of the screen do not change and do not change their order, you read the message and continue waiting for new messages.
Otherwise (i.e. if there is no conversation with idi on the screen):
Firstly, if the number of conversations displayed on the screen is k, the last conversation (which has the position k) is removed from the screen.
Now the number of conversations on the screen is guaranteed to be less than k and the conversation with the friend idi is not displayed on the screen.
The conversation with the friend idi appears on the first (the topmost) position on the screen and all the other displayed conversations are shifted one position down.
Your task is to find the list of conversations (in the order they are displayed on the screen) after processing all n messages.
思路:
队列维护, map记录, 模拟即可.
代码:
#include <bits/stdc++.h>
using namespace std;
map<int, bool> Mp;
deque<int> Que;
int n, k;
int main()
{
int id;
scanf("%d%d", &n, &k);
for (int i = 1;i <= n;i++)
{
scanf("%d", &id);
if (!Mp[id])
{
Que.push_front(id);
Mp[id] = true;
}
if (Que.size() > k)
{
int tmp = Que.back();
Que.pop_back();
Mp[tmp] = false;
}
}
printf("%d\n", (int)Que.size());
while (!Que.empty())
{
printf("%d ", Que.front());
Que.pop_front();
}
return 0;
}
Codeforces Round #590 (Div. 3) B2. Social Network (hard version)的更多相关文章
- Codeforces Round #599 (Div. 2) B2. Character Swap (Hard Version) 构造
B2. Character Swap (Hard Version) This problem is different from the easy version. In this version U ...
- Codeforces Round #599 (Div. 2) B2. Character Swap (Hard Version)
This problem is different from the easy version. In this version Ujan makes at most 2n2n swaps. In a ...
- Codeforces Round #590 (Div. 3) Editorial
Codeforces Round #590 (Div. 3) Editorial 题目链接 官方题解 不要因为走得太远,就忘记为什么出发! Problem A 题目大意:商店有n件商品,每件商品有不同 ...
- Codeforces Round #590 (Div. 3)
A. Equalize Prices Again 题目链接:https://codeforces.com/contest/1234/problem/A 题意:给你 n 个数 , 你需要改变这些数使得这 ...
- Codeforces Round #590 (Div. 3)(e、f待补
https://codeforces.com/contest/1234/problem/A A. Equalize Prices Again #include<bits/stdc++.h> ...
- Codeforces Round #595 (Div. 3)B2 简单的dfs
原题 https://codeforces.com/contest/1249/problem/B2 这道题一开始给的数组相当于地图的路标,我们只需对每个没走过的点进行dfs即可 #include &l ...
- Codeforces Round #590 (Div. 3)【D题:26棵树状数组维护字符出现次数】
A题 题意:给你 n 个数 , 你需要改变这些数使得这 n 个数的值相等 , 并且要求改变后所有数的和需大于等于原来的所有数字的和 , 然后输出满足题意且改变后最小的数值. AC代码: #includ ...
- Codeforces Round #590 (Div. 3)【D题:维护26棵树状数组【好题】】
A题 题意:给你 n 个数 , 你需要改变这些数使得这 n 个数的值相等 , 并且要求改变后所有数的和需大于等于原来的所有数字的和 , 然后输出满足题意且改变后最小的数值. AC代码: #includ ...
- Codeforces Round #590 (Div. 3) E. Special Permutations
链接: https://codeforces.com/contest/1234/problem/E 题意: Let's define pi(n) as the following permutatio ...
随机推荐
- *#【Python】【基础知识】【运算符】【Python的几类运算符】
Python的运算符分为以下几类: 算术运算符比较(关系)运算符赋值运算符逻辑运算符位运算符成员运算符身份运算符 以及需要考虑的:运算符优先级 一.算术运算符: 需要注意的,上图是Python 2.0 ...
- PowerPoint储存此文件时发生错误 出现错误的问题解决方法
.单击“文件”,单击“选项”,然后单击“加载项”. . 在管理下拉框中选择“COM加载项”,单击“转到”按钮. . 检查是否存在有任何加载项,清除所有复选框来禁用它们. . 关闭PPT并重新启动,测试 ...
- Git初始化配置以及配置github
1,配置用户名和邮箱(这里是我github中配置的用户名和邮箱),执行下面命令后,在C:\Users\yaosq盘下会出现一个全局文件.gitconfig. git config --global u ...
- Redis 数据结构 & 原理 & 持久化
一 概述 redis是一种高级的key-value数据库,它跟memcached类似,不过数据可以持久化,而且支持的数据类型也很丰富. Redis支持五种数据类型:string(字符串),hash(哈 ...
- Centos7下,宿主机nginx配合docker环境的php-fpm
一.安装docker并启动 yum install docker systemctl start docker 二.安装nginxCentOS 7默认不能从yum中安装nginx,原因可以自己搜索一下 ...
- 基于docker的mongodb安装以及PHP使用
说明:用docker基于单服务器,虚拟多个服务器的方案, 以下是两个config服务器,两个分片,以及每个分片有一个副本的方案 这里关于给mongodb设置远程密码的问题,我采取了用两个compser ...
- 内存溢出,内存泄漏,CPU溢出区别
内存溢出 out of memory,就是你要的内存空间超过了系统实际分配给你的空间,此时系统相当于没法满足你的需求,就会报内存溢出的错误 内存泄漏是指你向系统申请分配内存进行使用(new),可是使用 ...
- linux下mysql部署
mysql 1.拓扑结构 mysql集群有如下三层: 应用程序层:负责与mysql服务器通信的各种应用程序. Mysql服务器层:处理SQL命令,并与NDB存储引擎通信和Mysql服务器. NDB集群 ...
- shell习题第17题:检测磁盘
[题目要求] 写一个shell脚本,检测所有磁盘分区使用率和inode使用率并记录到以当天日期命名的日志文件里,当发现某个分区容量或者inode使用量大于85%时候,发邮件提醒 [核心要点] df d ...
- .Net C# 签名字符串排序
#region Get Sign Content /// <summary> /// Get Sign Content /// </summary> /// <param ...