QN01  XOR Game
Problem Statement
You are given an array of n integers ( 0 <= n <= 1000 ). Find a contiguous subsequence of these numbers [ a_{i}, a_{j} ] ( 1 <= i, j <= n ), such that the ExclusiveOR of these numbers is maximum. ( That is, a_{i} XOR a_{i+1} XOR... a_{j} should be maximum ).
Input
The test case contains exactly 2 lines of input.
The first line contains a single integer n ( 0 <= n <= 1000 ), the total number of integers in the sequence given to you.
The next line contains n space separated integers such that the ith integer denotes a_{i}. ( 0 <= a_{i} <= 10^{9} ). Note that these integers need not necessarily be distinct.
Output
Output two lines. In the first line, print out the value of the maximum XOR.
In the second line, print out i and j with a space separating them, such that [ a_{i}, a_{j} ] ( both endpoints inclusive ) denotes the contiguous subsequence with the maximum XOR value.
In case there is more than one subsequence with the maximum XOR value, print out the pair ( i, j ) such that ( i, j ) is lexicographically smallest. ( Formally, we say that a pair ( a, b ) is lexicographically smaller than another pair ( c,d ) if and only if (i) a < c or (ii) a=c and b < d. )
NOTE : The subsequence must be nonempty, but may be allowed to contain just one integer. ( i.e, in this case, i = j )
Example
Input #1:
1
4
Output #1:
4
1 1
Input #2:
3
1 2 3
Output #2:
3
1 2
Explanation:
 In the first test case, since there is only one number, the maximum XOR would be simply the value of that number ( in this case, 4 ), and i = j = 1.
 In the second test case, the maximum XOR value is 3, but there are 2 contiguous subsequences that define the same XOR value  (i) [ 1, 2 ] since 1 XOR 2 = 3 (ii) [ 3, 3 ] since this subsequence contains just the single integer 3. But since [ 1, 2 ] is lexicographically smaller than [ 3, 3 ], [ 1, 2 ] is the desired output.
hide comments
amulyagaur:
20180715 18:30:36
SAME PROBLEM WITH BETTER CONSTRAINTS : https://icpcarchive.ecs.baylor.edu/index.php?Itemid=8&category=345&option=com_onlinejudge&page=show_problem&problem=2683 

vengatesh15:
20170214 11:23:27
easy one.. 

sushanth_r:
20170125 12:19:32
AC in one go. Didn't expect that. Last edit: 20170125 12:21:58 

sushanth_r:
20170125 12:19:31
O(n^2) passes.... that too with 0.0 s 

Sarthak Munshi:
20160909 20:35:42
lol . O(n^2) passes ! 

anuj0503:
20160623 11:31:42
Just trie !! ;) 0.0sec Last edit: 20160705 18:30:24 

aspro:
20160601 23:24:07
better use "trie" than the brute force approach.... 

epsilon:
20160118 13:06:10
poor test cases !!! wondering how O(n^2) got accepted 

thirupathireddy:
20150628 03:47:01
what is O(nlogn) algorithm.......? 

psyclaudeZ:
20140805 22:03:27
...Why would I use long long 
Added by:  Gowri Sundaram 
Date:  20121112 
Time limit:  1s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All except: ASM64 