For the final calibration, Nusrat must scan a whole log of sensor readings and find the contiguous stretch whose XOR is the largest possible, to detect the noisiest window. Read N integers. Find the maximum XOR value of any contiguous subarray (XOR of all elements in that subarray). Use a prefix-XOR array plus a binary trie for O(N log(maxVal)), not brute force O(N^2).
Input
Line1: N. Line2: N integers.
Output
Maximum XOR of any contiguous subarray.
Constraints
1 ≤ N ≤ 10^5, 0 ≤ a_i ≤ 10^9
Sample Input
4 1 2 3 4
Sample Output
7
main.c
Loading editor…
Write C, then Run (custom I/O) or Submit (sample tests). ⌘/Ctrl+Enter submits.