CF1000F.One Occurrence

提高+/省选-

通过率:0%

时间限制:3.00s

内存限制:768MB

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?

给你一个包含 nn 个整数的数组 aa,以及 qq 个对该数组的查询。第 ii 个查询由两个整数 lil_i 和 rir_i 表示。对于每个查询,你需要在数组 aa 从下标 lil_i 到下标 rir_i 的子数组(子数组是数组的一个连续子段)中,找出任意一个恰好出现一次的整数。例如,若 a=[1,1,2,3,2,4]a = [1, 1, 2, 3, 2, 4],则对于查询 (li=2,ri=6)(l_i = 2, r_i = 6),我们关注的子数组为 [1,2,3,2,4][1, 2, 3, 2, 4],可能的答案有 11、33 和 44;而对于查询 (li=1,ri=2)(l_i = 1, r_i = 2),我们关注的子数组为 [1,1][1, 1],此时不存在恰好出现一次的元素。

你能回答所有这些查询吗?

输入格式

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

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

The third line contains one integer qq (1≤q≤5⋅1051 \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 (1≤li≤ri≤n1 \le l_i \le r_i \le n).

第一行包含一个整数 nn(1≤n≤5⋅1051 \le n \le 5 \cdot 10^5)。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤5⋅1051 \le a_i \le 5 \cdot 10^5)。

第三行包含一个整数 qq(1≤q≤5⋅1051 \le q \le 5 \cdot 10^5)。

接下来是 qq 行,其中第 ii 行包含两个整数 lil_i 和 rir_i,表示第 ii 个查询(1≤li≤ri≤n1 \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.

按以下方式回答查询:

如果在从索引 lil_i 到索引 rir_i 的子数组中,不存在恰好出现一次的整数,则输出 00;否则,输出任意一个满足条件的整数。

输入输出样例

  • 输入#1

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

    输出#1

    4
    0

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

首页