#PS0000131. Đoạn có điểm lớn nhất (bản dễ) (Sheikh (Easy Version))
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đoạn có điểm lớn nhất (bản dễ) (Sheikh (Easy Version))
Sheikh (Easy Version)
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
An array of nonnegative integers is given. For a nonempty contiguous interval , define its score as
$$f(l,r)=\sum_{i=l}^{r}a_i-(a_l\oplus a_{l+1}\oplus\cdots\oplus a_r).$$Here means bitwise XOR. Each of the queries specifies . Select an interval contained in that range with maximum score. Among maximum-score intervals, minimize . If several intervals still qualify, any is accepted. Queries do not modify the array.
Input
-
First line: integers .
-
Second line: integers .
-
Next lines: query contains integers ; the first query is .
Output
Print lines in query order, each with the two integer endpoints of a selected interval.
Subtasks
- Subtask 1 (20 points): ; ; ; ; ; ; .
- Subtask 2 (30 points): ; ; ; ; ; ; . Every .
- Subtask 3 (50 points): ; ; ; ; ; ; .
Example 1
Input
5 1
21 32 32 32 10
1 5
Output
2 3
Explanation
The whole array has sum 127 and XOR 63, giving score 64. Segment has sum 64 and XOR 0, so it reaches 64 with two elements. A singleton scores zero. Segment is also valid.
Example 2
Input
2 1
5 10
1 2
Output
1 1
Explanation
The whole array has sum and XOR 15, so its score is zero. Both singletons also score zero; either is optimal because length 1 is minimal.