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

#PS0000115. XOR các đoạn con (XOR Queries of a Subarray)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

XOR các đoạn con (XOR Queries of a Subarray)

XOR Queries of a Subarray

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

An array of nn positive integers a0,a1,…,an−1a_0,a_1,\ldots,a_{n-1} is indexed from 0. For each of qq queries (l,r)(l,r), compute the bitwise XOR from ala_l through ara_r, inclusive. XOR, denoted ⊕\oplus, sets a bit to 1 when the corresponding operand bits differ. All queries use the unchanged array.

Input

The first line contains integers n,qn,q.

The second line contains nn integers a0,…,an−1a_0,\ldots,a_{n-1}.

Each of the next qq lines contains integers l,rl,r.

Output

Print qq lines, each containing the answer to the corresponding query.

Subtasks

  • Subtask 1 (20 points): 1≤n,q≤1001\le n,q\le 100; 1≤ai≤1091\le a_i\le 10^9; 0≤i<n0\le i<n; 0≤l≤r<n0\le l\le r<n.
  • Subtask 2 (30 points): 1≤n,q≤3⋅1041\le n,q\le 3\cdot 10^4; 1≤ai≤1091\le a_i\le 10^9; 0≤i<n0\le i<n; 0≤l≤r<n0\le l\le r<n; r−l+1≤10r-l+1\le 10.
  • Subtask 3 (50 points): 1≤n,q≤3⋅1041\le n,q\le 3\cdot 10^4; 1≤ai≤1091\le a_i\le 10^9; 0≤i<n0\le i<n; 0≤l≤r<n0\le l\le r<n.

Example 1

Input

4 4
1 3 4 8
0 1
1 2
0 3
3 3

Output

2
7
14
8

Explanation

With zero-based positions, the ranges give 1⊕3=21\oplus3=2, 3⊕4=73\oplus4=7, 1⊕3⊕4⊕8=141\oplus3\oplus4\oplus8=14, and 88.

Example 2

Input

4 4
4 8 2 10
2 3
1 3
0 0
0 3

Output

8
0
4
4

Explanation

Range [2,3][2,3] gives 2⊕10=82\oplus10=8; range [1,3][1,3] gives 8⊕2⊕10=08\oplus2\oplus10=0. The singleton [0,0][0,0] gives 4; the whole array gives 4⊕0=44\oplus0=4.