链接:

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)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. Codeforces Round #590 (Div. 3) Editorial

    Codeforces Round #590 (Div. 3) Editorial 题目链接 官方题解 不要因为走得太远,就忘记为什么出发! Problem A 题目大意:商店有n件商品,每件商品有不同 ...

  4. Codeforces Round #590 (Div. 3)

    A. Equalize Prices Again 题目链接:https://codeforces.com/contest/1234/problem/A 题意:给你 n 个数 , 你需要改变这些数使得这 ...

  5. Codeforces Round #590 (Div. 3)(e、f待补

    https://codeforces.com/contest/1234/problem/A A. Equalize Prices Again #include<bits/stdc++.h> ...

  6. Codeforces Round #595 (Div. 3)B2 简单的dfs

    原题 https://codeforces.com/contest/1249/problem/B2 这道题一开始给的数组相当于地图的路标,我们只需对每个没走过的点进行dfs即可 #include &l ...

  7. Codeforces Round #590 (Div. 3)【D题:26棵树状数组维护字符出现次数】

    A题 题意:给你 n 个数 , 你需要改变这些数使得这 n 个数的值相等 , 并且要求改变后所有数的和需大于等于原来的所有数字的和 , 然后输出满足题意且改变后最小的数值. AC代码: #includ ...

  8. Codeforces Round #590 (Div. 3)【D题:维护26棵树状数组【好题】】

    A题 题意:给你 n 个数 , 你需要改变这些数使得这 n 个数的值相等 , 并且要求改变后所有数的和需大于等于原来的所有数字的和 , 然后输出满足题意且改变后最小的数值. AC代码: #includ ...

  9. Codeforces Round #590 (Div. 3) E. Special Permutations

    链接: https://codeforces.com/contest/1234/problem/E 题意: Let's define pi(n) as the following permutatio ...

随机推荐

  1. 使用pycharm开发web——django2.1.5(一)入坑尝试第一步,基本搭建

    首先,接触python的人应该都会用pip 来安装需要的包吧(------>>>>)默认 在运行中使用python -m django --version来检查自己的djang ...

  2. Double write Buffer的配置

    InnoDB和XtraDB使用称为doublewrite缓冲区的特殊功能来提供数据损坏的强大保证.想法是在写入数据文件之前将数据写入主表空间中的顺序日志.如果发生部分页面写入(换句话说,写入损坏),I ...

  3. 微信公众号通过用户授权获取用户基本信息java版

    公司需要开发一个微信公众号,要求用户通过公众号登录公司网站时候自动获取用户的基本信息,在网上查资料发现大部分都是直接copy微信公众平台的开发文档,感觉还是介绍的不是太小白,所以为了方便大家也为了自己 ...

  4. 基于NIO写的阻塞式和非阻塞式的客户端服务端

    由于功能太过简单,就不过多阐述了,直接上阻塞式代码: package com.lql.nio; import org.junit.Test; import java.io.IOException; i ...

  5. 【2019NOIP复习计划】

    (其实不应该这么叫的,应该是CSP-S了现在..) 重点关注的板子: 不知道为什么特别受出题人青睐的LCA(板子点这里) 配套练习:(紫题请自便)  (这题蓝的应该可以试试)  (对的这题也紫它还是道 ...

  6. DP单调队列--斜率优化P3195

    题意:https://www.luogu.com.cn/problem/P3195 思路:https://www.luogu.com.cn/problemnew/solution/P3195 #def ...

  7. zookeeper集群搭建与升级

    zookeeper 1.zookeeper功能 1-1.配置管理 集中管理配置文件实现服务治理 1-2.命名服务 如为了通过网络访问一个系统,我们得知道对方的IP地址,但是IP地址对人非常不友好,这个 ...

  8. MyBatis学习存档(3)——mapper.xml映射文件

    MyBatis 真正的强大在于映射语句,专注于SQL,功能强大,SQL映射的配置却是相当简单 所以我们来看看映射文件的具体结构 一.xml节点结构 mapper为根节点 - namespace命名空间 ...

  9. S03_CH03_AXI_DMA_OV7725摄像头采集系统

    S03_CH03_AXI_DMA_OV7725摄像头采集系统 3.1概述 本课程讲解如何搭建基于DMA的图形系统,方案原理如下. 摄像头采样图像数据后通过DMA送入到DDR,在PS部分产生DMA接收中 ...

  10. PowerDesigner最基础的使用方法

    1:入门级使用PowerDesigner软件创建数据库(直接上图怎么创建,其他的概念知识可自行学习) 我的PowerDesigner版本是16.5的,如若版本不一样,请自行参考学习即可.(打开软件即是 ...