when you are calculating result take only those elements which increases the result instead of xoring all the elements.
The Spoj link opens to problem XMAS . Recheck the link .
the two problems have same problem code! Just google “Xor Maximization Spoj”.You’ll get the problem statement