CF886B.Vlad and Cafes

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Vlad likes to eat in cafes very much. During his life, he has visited cafes n times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.

First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes he visited in a row, in order of visiting them. Now, Vlad wants to find such a cafe that his last visit to that cafe was before his last visits to every other cafe. In other words, he wants to find such a cafe that he hasn't been there for as long as possible. Help Vlad to find that cafe.

弗拉德非常喜欢在咖啡馆用餐。他一生中总共去过咖啡馆 nn 次。不幸的是,弗拉德开始觉得他最近几次的访问彼此之间毫无区别。为了改善这种情况,弗拉德做了一项小研究。

首先,弗拉德为所有咖啡馆分配了唯一的编号。接着,他按访问顺序依次写下所去咖啡馆的编号。现在,弗拉德希望找出这样一家咖啡馆:他对该咖啡馆的最后一次访问,早于他对其他任意一家咖啡馆的最后一次访问。换言之,他希望找出这样一家咖啡馆:他距离上一次光顾它的时间最长。请帮助弗拉德找出这家咖啡馆。

输入格式

In first line there is one integer n (1 ≤ n ≤ 2·105) — number of cafes indices written by Vlad.

In second line, n numbers _a_1, _a_2, ..., a__n (0 ≤ a__i ≤ 2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, some indices could be omitted.

第一行包含一个整数 nn(1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5)—— 表示弗拉德记录的咖啡馆编号个数。

第二行包含 nn 个整数 a1, a2, …, ana_1,\ a_2,\ \dots,\ a_n(0≤ai≤2⋅1050 \leq a_i \leq 2 \cdot 10^5)—— 表示弗拉德按访问顺序记录的咖啡馆编号。弗拉德可能多次访问同一间咖啡馆。注意:编号序列中可能存在空缺。

输出格式

Print one integer — index of the cafe that Vlad hasn't visited for as long as possible.

输出一个整数——Vlad 最久未访问的咖啡馆的编号。

输入输出样例

  • 输入#1

    5
    1 3 2 1 2

    输出#1

    3
  • 输入#2

    6
    2 1 2 2 4 1

    输出#2

    2

说明/提示

In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer.

In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with index 2, so the answer is 2. Note that Vlad could omit some numbers while numerating the cafes.

在第一个测试用例中,共有三家咖啡馆,编号为 1 和 2 的咖啡馆的最后一次访问均发生在编号为 3 的咖啡馆的最后一次访问之后;因此答案是咖啡馆 3。

在第二个测试用例中,同样有三家咖啡馆,但编号为 1、2 和 4。编号为 1 和 4 的咖啡馆的最后一次访问均发生在编号为 2 的咖啡馆的最后一次访问之后,因此答案是 2。注意:Vlad 在给咖啡馆编号时可能跳过某些数字。

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

首页