B. Vlad and Cafes
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Input

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

In second line, n numbers a1, a2, ..., an (0 ≤ ai ≤ 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.

Output

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

Examples
input
5
1 3 2 1 2
output
3
input
6
2 1 2 2 4 1
output
2
Note

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.

【题意】: 找到一个数满足,它最后一次出现的位置是i,位置i+1到n所有其他数字都出现过至少一次 。

【分析】: 1.上一次当彼佳参观每一家咖啡馆时,将其放在数组中。 2.现在你需要找到这个数组中最小的位置并打印它。

【代码】:

#include <bits/stdc++.h>

using namespace std;

const int maxn = 1e5+1e5+;
const int inf = ;
int vis[maxn];
int main()
{
int n,a;
int min;
int m;
while(cin>>n)
{
min=,m=-;
for(int i=;i<=n;i++)
{
cin>>a;
vis[a]=i;
} for(int i=;i<=;i++)
{
if(vis[i]&&vis[i]<min)
{
min=vis[i];
m=i;
}
}
cout<<m<<endl; }
}

Codeforces Round #445 B. Vlad and Cafes【时间轴】的更多相关文章

  1. Codeforces Round #445

    ACM ICPC 每个队伍必须是3个人 #include<stdio.h> #include<string.h> #include<stdlib.h> #inclu ...

  2. 【Codeforces Round #445 (Div. 2) B】Vlad and Cafes

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 傻逼模拟 [代码] #include <bits/stdc++.h> using namespace std; cons ...

  3. Codeforces Round #445 Div. 1

    A:每次看是否有能走回去的房间,显然最多只会存在一个,如果有走过去即可,否则开辟新房间并记录访问时间. #include<iostream> #include<cstdio> ...

  4. Codeforces Round #445 C. Petya and Catacombs【思维/题意】

    C. Petya and Catacombs time limit per test 1 second memory limit per test 256 megabytes input standa ...

  5. Codeforces Round #445 Div. 1 C Maximum Element (dp + 组合数学)

    题目链接: http://codeforces.com/contest/889/problem/C 题意: 给你 \(n\)和 \(k\). 让你找一种全排列长度为\(n\)的 \(p\),满足存在下 ...

  6. Codeforces Round #445 D. Restoration of string【字符串】

    D. Restoration of string time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  7. Codeforces Round #445 A. ACM ICPC【暴力】

    A. ACM ICPC time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...

  8. 【Codeforces Round #445 (Div. 2) D】Restoration of string

    [链接] 我是链接,点我呀:) [题意] 给你n个字符串. 让你构造一个字符串s. 使得这n个字符串. 每个字符串都是s的子串. 且都是出现次数最多的子串. 要求s的长度最短,且s的字典序最小. [题 ...

  9. 【Codeforces Round #445 (Div. 2) C】 Petya and Catacombs

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 看看时间戳为i的点有哪些. 每次优先用已经访问过的点. 如果不行就新创一个点. 注意新创点的时间戳也是i. [代码] #includ ...

随机推荐

  1. 《Cracking the Coding Interview》——第16章:线程与锁——题目2

    2014-04-27 19:14 题目:如何测量上下文切换的时间? 解法:首先,上下文切换是什么,一搜就知道.对于这么一个极短的时间,要测量的话,可以通过放大N倍的方法.比如:有A和B两件事,并且经常 ...

  2. sublime text基本配置备份

    sublime text基本配置备份: // Settings in here override those in "Default/Preferences.sublime-settings ...

  3. 【Count Complete Tree Nodes】cpp

    题目: Given a complete binary tree, count the number of nodes. Definition of a complete binary tree fr ...

  4. 关于mysqldump备份非事务表的注意事项

      Preface       We're used to get a logical backup set(whole instance) by simply specifying "-- ...

  5. JMeter学习笔记(三) 录制脚本

    jmeter测试脚本,可以通过其他工具进行录制,例如 BadBoy,我之前使用过此工具,安装以及使用都比较简单的,大家可以在网上搜索一下. 在此整理一下jmeter自带的录制功能,进行录制脚本. 1. ...

  6. mac虚拟机上(centos系统)设置联网第二种方式

    这种方式简单,不容易出错,用的桥接的方式. 这样的安装的centos会得到ip地址 然后编辑一下网卡配置,使其变为静态得ip 输入命令 # vi /etc/sysconfig/network-scri ...

  7. 【已解决】UBuntu16.04软件中心更新后只有桌面

    出现问题之前 安装好系统之后,成功启动系统,根据软件中心提示,升级电脑安装的软件,如下图所示.点击install(安装)开始更新,之后无任何提示,其实这个时候已经出现了升级异常. 呈现问题 操作步骤一 ...

  8. gulp-API介绍

    使用gulp,一般只需要用4个API:gulp.src(),gulp.dest(),gulp.task(),gulp.watch(). 1. gulp.src() 用来获取流的,但是要注意的是这个流里 ...

  9. Redis Sorted Set

    Redis Sorted Set Redis 有序集合和集合一样也是string类型元素的集合,且不允许重复的成员. 不同的是每个元素都会关联一个double类型的分数.redis正是通过分数来为集合 ...

  10. H3C交换机端口链路聚合

    H3C交换机端口链路聚合 以太网链路聚合 -- 以太网链路聚合配置命令 -- lacp system-prioritylacp system-priority命令用来配置系统的LACP优先级.undo ...