PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#SRD0000080. XOR trên các đoạn giá trị (Xors on Segments)
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 trên các đoạn giá trị (Xors on Segments)
Xors on Segments
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Define for . For each index range , choose indices (possibly the same) with and maximize . The XOR spans all consecutive integers from the smaller to the larger value.
Input
Read , the array, and inclusive ranges.
Output
Print the maximum XOR value for each query.
Subtasks
- Subtask 1 (10 points): , . ; .
- Subtask 2 (20 points): , . ; .
- Subtask 3 (25 points): , . ; .
- Subtask 4 (45 points): , . ; .
Examples
Input
6 3
1 2 3 4 5 6
1 6
2 5
3 4
Output
7
7
7
Explanation
Range contains values 3 and 4, so . All other choices in this small range give at most 7; the two larger ranges also contain this pair and have maximum 7.