Sub-array functions

4.9

10 votes
Approved, Basic Programming, Bit manipulation, Easy, Grammar-Verified, Implementation, Priority queue, Ready, Recruit
Problem

You are given an array A containing N integers. The following functions are defined for this array:

  • f1(l,r)=XOR of the first M smallest elements in the subarray from l to r, lr and rl+1M
  • f2(l,r)=XOR of the first P largest elements in the subarray from l to r, lr and rl+1P
  • f3(l,r)=f1(l,r) & f2(l,r), lr

Write a program to find l and r such that f3(l,r) is maximum. If there are several values of l and r for which f3(l,r) is maximum, return the one having the largest length. If multiple values still exist, return the one with the smallest l.

Input format

  • First line: T (number of test cases)
  • First line in each test case: Three space-separated integers denoting N,M, and P respectively.
  • Second line in each test case: N space-separated integers (denoting the array A)

Output format

For each test case, print three space-separated integers denoting l, r, and f3(l,r).

Constraints

1T5
1N2000
1M,PN
0A[i]109

Sample Input
2
4 2 2
1 2 3 4
5 2 1
1 2 3 4 5
Sample Output
3 4 7
3 5 5
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

In the Case 1 : since M=P=2 so we require a sub-array with a length of atleast 2. {3,4} is giving a maximum possible value of f3(l,r).

Editor Image

?