#BS0000171. Sheikh – phiên bản khó (Sheikh (Hard Version))
Bài tập thuộc lộ trình
Mục lục đề ⌄
Sheikh – phiên bản khó (Sheikh (Hard Version))
Sheikh (Hard Version)
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You are given an array of nonnegative integers. For a contiguous subarray , let
where is bitwise XOR. The value of this subarray is .
There are queries. Query specifies . Find a subarray completely inside that maximizes . Among all maximizing subarrays, choose one of minimum length . If several answers remain, output any of them.
The first query is always .
Input
- The first line contains , where .
- The second line contains exactly nonnegative integers .
- Each of the next lines contains with the query boundaries. It is guaranteed that .
Output
Print exactly lines. Line must contain indices of a maximizing segment within , of minimum length among all maximizing segments.
Subtasks
- Subtask 1 (20 points): ; for all ; for all ; .
- Subtask 2 (30 points): ; for all ; for all ; .
- Subtask 3 (50 points): ; for all ; for all ; .
Examples
Input
4 4
0 12 8 3
1 4
1 3
2 4
2 3
Output
2 3
2 3
2 3
2 3
Explanation
Segment contains : the sum is , the XOR is , and .
All four query intervals contain . The entire interval has sum and XOR , also producing ; has value too. Thus the maximum query value is , but is only two elements long and no one-element segment can have positive value. Consequently, each output line is 2 3.