CF1000F.One Occurrence
提高+/省选-
通过率:0%
时间限制:3.00s
内存限制:768MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an array a consisting of n integers, and q queries to it. i-th query is denoted by two integers li and ri. For each query, you have to find any integer that occurs exactly once in the subarray of a from index li to index ri (a subarray is a contiguous subsegment of an array). For example, if a=[1,1,2,3,2,4], then for query (li=2,ri=6) the subarray we are interested in is [1,2,3,2,4], and possible answers are 1, 3 and 4; for query (li=1,ri=2) the subarray we are interested in is [1,1], and there is no such element that occurs exactly once.
Can you answer all of the queries?
给你一个包含 n 个整数的数组 a,以及 q 个对该数组的查询。第 i 个查询由两个整数 li 和 ri 表示。对于每个查询,你需要在数组 a 从下标 li 到下标 ri 的子数组(子数组是数组的一个连续子段)中,找出任意一个恰好出现一次的整数。例如,若 a=[1,1,2,3,2,4],则对于查询 (li=2,ri=6),我们关注的子数组为 [1,2,3,2,4],可能的答案有 1、3 和 4;而对于查询 (li=1,ri=2),我们关注的子数组为 [1,1],此时不存在恰好出现一次的元素。
你能回答所有这些查询吗?
输入格式
The first line contains one integer n (1≤n≤5⋅105).
The second line contains n integers a1,a2,…,an (1≤ai≤5⋅105).
The third line contains one integer q (1≤q≤5⋅105).
Then q lines follow, i-th line containing two integers li and ri representing i-th query (1≤li≤ri≤n).
第一行包含一个整数 n(1≤n≤5⋅105)。
第二行包含 n 个整数 a1,a2,…,an(1≤ai≤5⋅105)。
第三行包含一个整数 q(1≤q≤5⋅105)。
接下来是 q 行,其中第 i 行包含两个整数 li 和 ri,表示第 i 个查询(1≤li≤ri≤n)。
输出格式
Answer the queries as follows:
If there is no integer such that it occurs in the subarray from index li to index ri exactly once, print 0. Otherwise print any such integer.
按以下方式回答查询:
如果在从索引 li 到索引 ri 的子数组中,不存在恰好出现一次的整数,则输出 0;否则,输出任意一个满足条件的整数。
输入输出样例
输入#1
6 1 1 2 3 2 4 2 2 6 1 2
输出#1
4 0
输入解题思路,AI测评打分。不知道怎么写?