Benny and Queries
Practice
4.2 (43 votes)
Trie
Approved
Medium Hard
Greedy algorithm
Problem
79% Success 1129 Attempts 50 Points 4s Time Limit 512MB Memory 1024 KB Max Code
Probably, you have already read some problems but you still have not met any problems with queries on segments. Therefore Benny wants to fix it.
She gives you an array A of N elements. And then you have to answer Q queries.
Each query consists of three integers L, R, X. Your task is to find such Ai, that L ≤ i ≤ R and Ai xor X is maximal. For each query output the maximum of Ai xor X.
Input format
The first line contains two integers N and Q. The next line contains N integers Ai. The next Q lines contain three integers L, R, X.
Output format
For each query output the maximum of Ai xor X in a single line.
Constraints
- 1 ≤ N, Q ≤ 5 * 105
- 0 ≤ Ai < 220
- 1 ≤ L ≤ R ≤ N
- 0 ≤ X < 220
- 1 ≤ N, Q ≤ 3 * 103 holds for test cases worth 15% of the problem's score.
- 1 ≤ N, Q ≤ 105 holds for test cases worth 60% of the problem's score.
Submissions
Please login to view your submissions
Similar Problems
Points:20
39 votes
Tags:
AlgorithmsApprovedBreadth First SearchEasyGraphsOpen
Points:30
57 votes
Tags:
ApprovedBit ManipulationCombinatoricsEasyMathOpenReady
Points:50
Tags:
MathematicsHardApprovedRecruit
Editorial