PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#FT0000131. Mishka và phép XOR thú vị (Mishka and Interesting Sum)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Mishka và phép XOR thú vị (Mishka and Interesting Sum)

Mishka and Interesting Sum

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Given a sequence a1,…,ana_1,\ldots,a_n of positive integers, answer mm closed interval queries [l,r][l,r].

For each interval, take each distinct value that occurs a positive even number of times, exactly once, and XOR all such values. Values with odd frequency are excluded. Print zero if no value qualifies.

For example, in 1 2 1 2 2 3 3, values 1 and 3 occur twice, while 2 occurs three times, so the answer is 1⊕3=21\oplus3=2. This is not the XOR of all elements.

Input

  • First line: nn.
  • Second line: nn values aia_i.
  • Third line: mm.
  • Next mm lines: one query l,rl,r each.

Output

Print one nonnegative XOR result per query, in input order.

Subtasks

  • Subtask 1 (20 points): 1≤n≤401\le n\le 40; 1≤m≤401\le m\le 40; 1≤ai≤1091\le a_i\le10^9; 1≤l≤r≤n1\le l\le r\le n, where 4040 is the maximum nn in this subtask.
  • Subtask 2 (30 points): 1≤n≤40001\le n\le 4000; 1≤m≤40001\le m\le 4000; 1≤ai≤1091\le a_i\le10^9; 1≤l≤r≤n1\le l\le r\le n, where 40004000 is the maximum nn in this subtask.
  • Subtask 3 (50 points): 1≤n≤10000001\le n\le 1000000; 1≤m≤10000001\le m\le 1000000; 1≤ai≤1091\le a_i\le10^9; 1≤l≤r≤n1\le l\le r\le n, where 10000001000000 is the maximum nn in this subtask.

Examples

Example 1

Input

3
3 7 8
1
1 3

Output

0

Explanation

All values of 3 7 8 in [1,3][1,3] occur once, so no value has a positive even frequency. The result is 0.

Example 2

Input

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

Output

0
3
1
3
2

Explanation

For [4,7] = 3 3 2 3, both values occur an odd number of times, yielding 0. [4,5] = 3 3 yields 3. [1,3] = 1 2 1 yields 1. In the full range, values 1 and 2 each occur twice, yielding 1⊕2=31\oplus2=3. Range [1,5] yields 1⊕3=21\oplus3=2.