Sub-array functions
Practice
4.9 (10 votes)
Approved
Basic programming
Bit manipulation
Easy
Grammar Verified
Implementation
Priority queue
Ready
Recruit
Problem
54% Success 1668 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code
You are given an array A containing N integers. The following functions are defined for this array:
- \(f_1(l,r) = \)XOR of the first M smallest elements in the subarray from l to r, \(l \le r\) and \(r-l+1 \ge M\)
- \(f_2(l,r) = \)XOR of the first P largest elements in the subarray from l to r, \(l \le r\) and \(r-l+1 \ge P\)
- \(f_3(l,r) = f_1(l,r) \space \& \space f_2(l,r)\), \(l \le r\)
Write a program to find l and r such that \(f_3(l,r)\) is maximum. If there are several values of l and r for which \(f_3(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 \(f_3(l,r)\).
Constraints
\(1 \le T \le 5\)
\(1 \le N \le 2000\)
\(1 \le M, P \le N\)
\(0 \le A[i] \le 10^9\)
Submissions
Please login to view your submissions
Similar Problems
Points:20
14 votes
Tags:
Basic ProgrammingBit Manipulation
Points:20
63 votes
Tags:
ApprovedBasic ProgrammingEasyMathOpen
Points:20
35 votes
Tags:
Ad-HocApprovedBasic ProgrammingEasyOpen
Editorial