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 ...
随机推荐
- 一个memset导致的血案
本文记录解答MIT 6.828 Lab 1 Exercise 10时遇到的一个Bug. 问题描述 在i386_init入口处设置断点并运行,发现执行memset(edata, 0, end - eda ...
- Spring4学习回顾之路12-事务
事务:事务就是一系列的动作,它们被当做一个单独的工作单元,这些动作要么全部完成,要么全部不起作用:事务管理是企业级应用程序开发中必不可少的技术,用来确保数据的完整性和一致性.事务的四个关键属性(ACI ...
- 在生产环境中使用Compose 【翻译】
在生产环境中使用Compose 在开发环境中使用Compose定义你的应用,可以使用此定义在不同的环境,(如 CI.暂存和生产)中运行应用程序. 部署应用程序的最简单方法是在单个服务器上运行该应用程序 ...
- 逆向知识第九讲,switch case语句在汇编中表达的方式
一丶Switch Case语句在汇编中的第一种表达方式 (引导性跳转表) 第一种表达方式生成条件: case 个数偏少,那么汇编中将会生成引导性的跳转表,会做出 if else的情况(类似,但还是能分 ...
- ie/chorme 清除缓存 刷新js,css
1 有时候你发现你刚改过的js 没有用,然后就是你的浏览器 没有清楚缓存,它可能还是保存的之前的 网页文件: chorme 浏览器下(版本:ver 59.0.3071.104(正式版本) (64 位) ...
- asp.net core 中hangfire面板的配置及使用
1.定义校验授权类DyDashboardAuthorizationFilter /// <summary> /// Hangfire仪表盘配置授权 /// </summary> ...
- TypeScript入门五:TypeScript的接口
TypeScript接口的基本使用 TypeScript函数类型接口 TypeScript可索引类型接口 TypeScript类类型接口 TypeScript接口与继承 一.TypeScript接口的 ...
- B站视频下载
借助Chrome插件 bilibili哔哩哔哩下载助手 在谷歌应用商城下载安装后在在浏览器右上角显示如下图标 打开想要下载的视频,网页右下角会有如下图标,点击该图标 点击下面的合并下载按钮即可 htt ...
- 阿里P8架构师总结Java并发面试题(精选)
一.什么是线程? 线程是操作系统能够进行运算调度的最小单位,它被包含在进程之中,是进程中的实际运作单位.程序员可以通过它进行多处理器编程,你可以使用多线程对运算密集型任务提速.比如,如果一个线程完成一 ...
- JavaSpring【二、IOC】
概述: 接口及面向接口编程 接口:用于沟通的中介物的抽象,实体把自己提供给外界的方法的抽象化说明,将声明和实现分离,使其能够改变内部而不影响与外部的交互方式 面向接口编程:在结构设计中,分清层次及调用 ...