CF703D.Mishka and Interesting sum

提高+/省选-

通过率:0%

时间限制:3.50s

内存限制:256MB

AC君温馨提醒

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

题目描述

Little Mishka enjoys programming. Since her birthday has just passed, her friends decided to present her with array of non-negative integers _a_1, _a_2, ..., a__n of n elements!

Mishka loved the array and she instantly decided to determine its beauty value, but she is too little and can't process large arrays. Right because of that she invited you to visit her and asked you to process m queries.

Each query is processed in the following way:

  1. Two integers l and r (1 ≤ l ≤ r ≤ n) are specified — bounds of query segment.
  2. Integers, presented in array segment [l,  r] (in sequence of integers a__l, a__l + 1, ..., a__r) even number of times, are written down.
  3. XOR-sum of written down integers is calculated, and this value is the answer for a query. Formally, if integers written down in point 2 are _x_1, _x_2, ..., x__k, then Mishka wants to know the value , where — operator of exclusive bitwise OR.

Since only the little bears know the definition of array beauty, all you are to do is to answer each of queries presented.

小 Mishka 喜欢编程。由于她的生日刚刚过去,朋友们决定送给她一个由 nn 个非负整数组成的数组 a1, a2, …, ana_1,\,a_2,\,\dots,\,a_n!

Mishka 非常喜欢这个数组,并立刻决定计算它的“美丽值”,但她年纪尚小,无法处理大型数组。正因如此,她邀请你去拜访她,并请你处理 mm 个查询。

每个查询按如下方式处理:

  1. 给定两个整数 ll 和 rr(满足 1≤l≤r≤n1 \leq l \leq r \leq n)—— 查询区间的左右边界;
  2. 将子数组段 [l, r][l,\,r](即序列 al, al+1, …, ara_l,\,a_{l+1},\,\dots,\,a_r)中出现偶数次的整数全部写下来;
  3. 计算所写下的这些整数的异或和(XOR-sum),该值即为该查询的答案。形式上,若第 2 步中写下的整数为 x1, x2, …, xkx_1,\,x_2,\,\dots,\,x_k,则 Mishka 想要知道的值为 ,其中 表示按位异或(exclusive bitwise OR)运算符。

由于只有小熊们才了解“数组美丽值”的定义,你所需要做的就是回答所给出的每一个查询。

输入格式

The first line of the input contains single integer n (1 ≤ n ≤ 1 000 000) — the number of elements in the array.

The second line of the input contains n integers _a_1, _a_2, ..., a__n (1 ≤ a__i ≤ 109) — array elements.

The third line of the input contains single integer m (1 ≤ m ≤ 1 000 000) — the number of queries.

Each of the next m lines describes corresponding query by a pair of integers l and r (1 ≤ l ≤ r ≤ n) — the bounds of query segment.

输入的第一行包含一个整数 nn(1≤n≤1 000 0001 \leq n \leq 1\,000\,000)—— 数组中元素的个数。

输入的第二行包含 nn 个整数 a1, a2, …, ana_1,\,a_2,\,\dots,\,a_n(1≤ai≤1091 \leq a_i \leq 10^9)—— 数组元素。

输入的第三行包含一个整数 mm(1≤m≤1 000 0001 \leq m \leq 1\,000\,000)—— 查询的个数。

接下来的 mm 行,每行描述一个查询,由一对整数 ll 和 rr(1≤l≤r≤n1 \leq l \leq r \leq n)给出—— 查询区间的左右端点。

输出格式

Print m non-negative integers — the answers for the queries in the order they appear in the input.

输出 m 个非负整数——即按输入中查询出现的顺序对应的答案。

输入输出样例

  • 输入#1

    3
    3 7 8
    1
    1 3

    输出#1

    0
  • 输入#2

    7
    1 2 1 3 3 2 3
    5
    4 7
    4 5
    1 3
    1 7
    1 5

    输出#2

    0
    3
    1
    3
    2

说明/提示

In the second sample:

There is no integers in the segment of the first query, presented even number of times in the segment — the answer is 0.

In the second query there is only integer 3 is presented even number of times — the answer is 3.

In the third query only integer 1 is written down — the answer is 1.

In the fourth query all array elements are considered. Only 1 and 2 are presented there even number of times. The answer is .

In the fifth query 1 and 3 are written down. The answer is .

在第二个样例中:

第一个查询的区间内没有出现偶数次的整数——答案为 0。

第二个查询中,只有整数 3 出现了偶数次——答案为 3。

第三个查询中,只写下了整数 1——答案为 1。

第四个查询考虑了整个数组的所有元素。其中仅 1 和 2 出现了偶数次。答案为 。

第五个查询中写下了 1 和 3。答案为 。

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

首页