CF1771F.Hossam and Range Minimum Query

省选/NOI-

通过率:0%

时间限制:1.50s

内存限制:256MB

AC君温馨提醒

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

题目描述

Hossam gives you a sequence of integers a1, a2, …, ana_1, \, a_2, \, \dots, \, a_n of length nn. Moreover, he will give you qq queries of type (l, r)(l, \, r). For each query, consider the elements al, al+1, …, ara_l, \, a_{l + 1}, \, \dots, \, a_r. Hossam wants to know the smallest number in this sequence, such that it occurs in this sequence an odd number of times.

You need to compute the answer for each query before process the next query.

霍萨姆给你一个长度为 nn 的整数序列 a1, a2, …, ana_1, \, a_2, \, \dots, \, a_n。此外,他还会给出 qq 个形如 (l, r)(l, \, r) 的查询。对于每个查询,考虑子序列 al, al+1, …, ara_l, \, a_{l + 1}, \, \dots, \, a_r。霍萨姆想知道该子序列中出现次数为奇数次的最小数字。

你需要在处理下一个查询之前,先为当前查询计算出答案。

输入格式

The first line of the input contains one integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5), the length of the sequence.

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

The third line contains one integer qq (1≤q≤2⋅1051 \le q \le 2 \cdot 10^5), the number of queries.

Each of the next qq lines contains two integers aa and bb (0≤a, b≤2⋅1090 \le a, \, b \le 2 \cdot 10^9), the numbers used to encode the queries.

Let ansi\mathrm{ans}_i be the answer on the ii-th query, and ans0\mathrm{ans}_0 be zero. Then $$l_i = a_i \oplus \mathrm{ans}_{i - 1},$$ $$r_i = b_i \oplus \mathrm{ans}_{i - 1},$$ where li, ril_i, \, r_i are parameters of the ii-th query and ⊕\oplus means the bitwise exclusive or operation. It is guaranteed that 1≤l≤r≤n1 \le l \le r \le n.

输入的第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5),表示序列的长度。

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

第三行包含一个整数 qq(1≤q≤2⋅1051 \le q \le 2 \cdot 10^5),表示查询的数量。

接下来的 qq 行中,每行包含两个整数 aa 和 bb(0≤a, b≤2⋅1090 \le a, \, b \le 2 \cdot 10^9),用于对查询进行编码。

设 ansi\mathrm{ans}_i 为第 ii 个查询的答案,且 ans0=0\mathrm{ans}_0 = 0。则

l_i=a_ioplusmathrmans_i−1,l\_i = a\_i \\oplus \\mathrm{ans}\_{i - 1},

r_i=b_ioplusmathrmans_i−1,r\_i = b\_i \\oplus \\mathrm{ans}\_{i - 1},

其中 li, ril_i, \, r_i 是第 ii 个查询的参数,⊕\oplus 表示按位异或运算。保证 1≤l≤r≤n1 \le l \le r \le n。

输出格式

For each query, print the smallest number that occurs an odd number of times on the given segment of the sequence.

If there is no such number, print 00.

对于每个查询,输出给定序列区间内出现奇数次的最小数字。

如果不存在这样的数字,则输出 00。

输入输出样例

  • 输入#1

    5
    1 2 1 2 2
    6
    1 2
    0 2
    0 6
    0 5
    2 2
    3 7

    输出#1

    1
    2
    1
    0
    2
    2
  • 输入#2

    10
    51 43 69 48 23 52 48 76 19 55
    10
    1 1
    57 57
    54 62
    20 27
    56 56
    79 69
    16 21
    18 30
    25 25
    62 61

    输出#2

    51
    55
    19
    48
    76
    19
    23
    19
    55
    19

说明/提示

In the example,

l\_1 = 1, \\, r\_1 = 2,$$ $$l\_2 = 1, \\, r\_2 = 3,$$ $$l\_3 = 2, \\, r\_3 = 4,$$ $$l\_4 = 1, \\, r\_4 = 4,$$ $$l\_5 = 2, \\, r\_5 = 2,$$ $$l\_6 = 1, \\, r\_6 = 5.

在示例中,

l\_1 = 1, \\, r\_1 = 2,$$ $$l\_2 = 1, \\, r\_2 = 3,$$ $$l\_3 = 2, \\, r\_3 = 4,$$ $$l\_4 = 1, \\, r\_4 = 4,$$ $$l\_5 = 2, \\, r\_5 = 2,$$ $$l\_6 = 1, \\, r\_6 = 5.

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

首页