codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

886B.md (1821B)


      1 Source: https://codeforces.com/problemset/problem/886/B
      2 
      3 B. Vlad and Cafes
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 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.
     22 
     23 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.
     24 
     25 Input
     26 
     27 In first line there is one integer *n* (1 ≤ *n* ≤ 2·105) — number of cafes indices written by Vlad.
     28 
     29 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.
     30 
     31 Output
     32 
     33 Print one integer — index of the cafe that Vlad hasn't visited for as long as possible.
     34 
     35 Examples
     36 
     37 Input
     38 
     39 ```
     40 5  
     41 1 3 2 1 2
     42 ```
     43 
     44 Output
     45 
     46 ```
     47 3
     48 ```
     49 
     50 Input
     51 
     52 ```
     53 6  
     54 2 1 2 2 4 1
     55 ```
     56 
     57 Output
     58 
     59 ```
     60 2
     61 ```
     62 
     63 Note
     64 
     65 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.
     66 
     67 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.