CF1000F.One Occurrence

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You are given an array aa consisting of nn integers, and qq queries to it. ii -th query is denoted by two integers lil_i and rir_i . For each query, you have to find any integer that occurs exactly once in the subarray of aa from index lil_i to index rir_i (a subarray is a contiguous subsegment of an array). For example, if a=[1,1,2,3,2,4]a = [1, 1, 2, 3, 2, 4] , then for query (li=2,ri=6)(l_i = 2, r_i = 6) the subarray we are interested in is [1,2,3,2,4][1, 2, 3, 2, 4] , and possible answers are 11 , 33 and 44 ; for query (li=1,ri=2)(l_i = 1, r_i = 2) the subarray we are interested in is [1,1][1, 1] , and there is no such element that occurs exactly once.

Can you answer all of the queries?

输入格式

The first line contains one integer nn ( 1n51051 \le n \le 5 \cdot 10^5 ).

The second line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n ( 1ai51051 \le a_i \le 5 \cdot 10^5 ).

The third line contains one integer qq ( 1q51051 \le q \le 5 \cdot 10^5 ).

Then qq lines follow, ii -th line containing two integers lil_i and rir_i representing ii -th query ( 1lirin1 \le l_i \le r_i \le n ).

输出格式

Answer the queries as follows:

If there is no integer such that it occurs in the subarray from index lil_i to index rir_i exactly once, print 00 . Otherwise print any such integer.

输入输出样例

  • 输入#1

    6
    1 1 2 3 2 4
    2
    2 6
    1 2
    

    输出#1

    4
    0
    
首页