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. 剑指Offer - 九度1351 - 数组中只出现一次的数字

    剑指Offer - 九度1351 - 数组中只出现一次的数字2013-11-23 01:23 题目描述: 一个整型数组里除了两个数字之外,其他的数字都出现了两次.请写程序找出这两个只出现一次的数字. ...

  2. leetcode 【 Linked List Swap Nodes in Pairs 】 python 实现

    题目: Swap Nodes in Pairs Given a linked list, swap every two adjacent nodes and return its head. For ...

  3. selenium + python之元素定位

    selenium对web各元素的操作首先就要先定位元素,定位元素的方法主要有以下几种:通过id定位元素:find_element_by_id("id_vaule")通过name定位 ...

  4. CodeForces-757B Bash's Big Day

    题目链接 https://vjudge.net/problem/CodeForces-757B 题目 Description Bash has set out on a journey to beco ...

  5. Python MySQLdb 模块使用方法

    import MySQLdb 2.和数据库建立连接 conn=MySQLdb.connect(host="localhost",user="root",pass ...

  6. DOM关于高度宽度位置的获取

    假设 obj 为某个 HTML 控件. obj.offsetTop 指 obj 相对于版面或由 offsetParent 属性指定的父坐标的计算上侧位置,整型,单位像素. obj.offsetLeft ...

  7. 什么是SQL注入?(理解)

    SQL注入攻击是黑客对数据库进行攻击的常用手段之一.一部分程序员在编写代码的时候,没有对用户输入数据的合法性进行判断,注入者可以在表单中输入一段数据库查询代码并提交,程序将提交的信息拼凑生成一个完整s ...

  8. HTTP3.0(QUIC的实现机制)

    回顾HTTP2.0 HTTP1.1在应用层以纯文本的形式进行通信,每次通信都要带完整的HTTP的头,而且不考虑pipeli模式的化,每次的过程总是像上面描述的那样一去一回.那样在实时性.并发想上都存在 ...

  9. Swift中由找不到removeAll(where:)方法引起的连锁反应(上)

    核心代码 section.removeAll {baseRow in if let habitRow = baseRow as? HabitRow{ let idxPath = habitRow.in ...

  10. BZOJ 1861: [Zjoi2006]Book 书架 | SPlay 板题

    #include<cstdio> #include<algorithm> #include<cstring> #define N 80010 #define whi ...