CF637B.Chat Order

普及-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list.

Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus.

Polycarp 非常喜欢在社交网络上消磨时间。他最喜爱的社交网络中,聊天列表页面的设计是:当向某位好友发送一条消息时,该好友的聊天会升至页面最顶端;其余聊天的相对顺序保持不变。如果此前不存在与这位好友的聊天,则直接在列表顶部插入一个新的聊天。

假设初始聊天列表为空,给定 Polycarp 发送的消息序列,请输出处理完所有消息后的最终聊天列表。假设没有任何好友向 Polycarp 发送过消息。

输入格式

The first line contains integer n (1 ≤ n ≤ 200 000) — the number of Polycarpus' messages. Next n lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10.

第一行包含一个整数 nn(1≤n≤200 0001 \leq n \leq 200\,000)—— 表示波利卡普斯发送的消息数量。接下来的 nn 行按消息发送顺序列出每条消息的接收者。每位参与者的姓名是一个非空的、由小写英文字母组成的字符串,长度至多为 10。

输出格式

Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom.

按聊天顺序(从上到下)打印 Polycarp 与之交谈过的所有收件人。

输入输出样例

  • 输入#1

    4
    alex
    ivan
    roman
    ivan

    输出#1

    ivan
    roman
    alex
  • 输入#2

    8
    alina
    maria
    ekaterina
    darya
    darya
    ekaterina
    maria
    alina

    输出#2

    alina
    maria
    ekaterina
    darya

说明/提示

In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:

  1. alex

Then Polycarpus writes to friend by name "ivan" and the list looks as follows:

  1. ivan
  2. alex

Polycarpus writes the third message to friend by name "roman" and the list looks as follows:

  1. roman
  2. ivan
  3. alex

Polycarpus writes the fourth message to friend by name "ivan", to who he has already sent a message, so the list of chats changes as follows:

  1. ivan
  2. roman
  3. alex

在第一个测试用例中,Polycarpus 首先给名为 “alex” 的朋友发送消息,此时聊天列表如下所示:

  1. alex

接着,Polycarpus 给名为 “ivan” 的朋友发送消息,此时聊天列表如下所示:

  1. ivan
  2. alex

Polycarpus 向名为 “roman” 的朋友发送第三条消息,此时聊天列表如下所示:

  1. roman
  2. ivan
  3. alex

Polycarpus 向名为 “ivan” 的朋友发送第四条消息(此前已向其发送过消息),因此聊天列表更新为:

  1. ivan
  2. roman
  3. alex

输入解题思路,AI测评打分。不知道怎么写?

首页