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
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
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 positive integers is indexed from 0. For each of queries , compute the bitwise XOR from through , inclusive. XOR, denoted , sets a bit to 1 when the corresponding operand bits differ. All queries use the unchanged array.
Input
The first line contains integers .
The second line contains integers .
Each of the next lines contains integers .
Output
Print lines, each containing the answer to the corresponding query.
Subtasks
- Subtask 1 (20 points): ; ; ; .
- Subtask 2 (30 points): ; ; ; ; .
- Subtask 3 (50 points): ; ; ; .
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 , , , and .
Example 2
Input
4 4
4 8 2 10
2 3
1 3
0 0
0 3
Output
8
0
4
4
Explanation
Range gives ; range gives . The singleton gives 4; the whole array gives .