PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#PS0000131. Đoạn có điểm lớn nhất (bản dễ) (Sheikh (Easy Version))

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Đ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 nn nonnegative integers a1,a2,…,ana_1,a_2,\ldots,a_n is given. For a nonempty contiguous interval [l,r][l,r], 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 ⊕\oplus means bitwise XOR. Each of the qq queries specifies Li,RiL_i,R_i. Select an interval [l,r][l,r] contained in that range with maximum score. Among maximum-score intervals, minimize r−l+1r-l+1. If several intervals still qualify, any is accepted. Queries do not modify the array.

Input

  • First line: integers n,qn,q.

  • Second line: nn integers a1,…,ana_1,\ldots,a_n.

  • Next qq lines: query ii contains integers Li,RiL_i,R_i; the first query is [1,n][1,n].

Output

Print qq lines in query order, each with the two integer endpoints l,rl,r of a selected interval.

Subtasks

  • Subtask 1 (20 points): 1≤n≤20001\le n\le 2000; q=1q=1; 0≤ai≤1090\le a_i\le 10^9; 1≤i≤n1\le i\le n; 1≤Li≤Ri≤n1\le L_i\le R_i\le n; 1≤i≤q1\le i\le q; L1=1, R1=nL_1=1,\ R_1=n.
  • Subtask 2 (30 points): 1≤n≤1051\le n\le 10^5; q=1q=1; 0≤ai≤1090\le a_i\le 10^9; 1≤i≤n1\le i\le n; 1≤Li≤Ri≤n1\le L_i\le R_i\le n; 1≤i≤q1\le i\le q; L1=1, R1=nL_1=1,\ R_1=n. Every ai≤1a_i\le 1.
  • Subtask 3 (50 points): 1≤n≤1051\le n\le 10^5; q=1q=1; 0≤ai≤1090\le a_i\le 10^9; 1≤i≤n1\le i\le n; 1≤Li≤Ri≤n1\le L_i\le R_i\le n; 1≤i≤q1\le i\le q; L1=1, R1=nL_1=1,\ R_1=n.

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 [2,3][2,3] has sum 64 and XOR 0, so it reaches 64 with two elements. A singleton scores zero. Segment [3,4][3,4] 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.