#C5412. Maximum XOR Subarray

    ID: 49059 Type: Default 1000ms 256MiB

Maximum XOR Subarray

Maximum XOR Subarray

You are given an array of integers. Your task is to determine the maximum XOR sum that can be obtained from any contiguous subarray of the given array.

Let \(a_1, a_2, \dots, a_n\) be the elements of the array. A subarray is defined by indices \(i\) and \(j\) (with \(1 \leq i \leq j \leq n\)), and its XOR sum is given by:

[ p = a_i \oplus a_{i+1} \oplus \cdots \oplus a_j ]

Your goal is to compute the maximum value of \(p\) over all subarrays.

Input Format: The input is read from stdin. The first integer \(T\) is the number of test cases. For each test case, the first number is an integer \(N\), representing the length of the array, followed by \(N\) integers that form the array.

Output Format: For each test case, print the maximum XOR subarray sum in a new line.

Constraints: It is guaranteed that the input size is reasonable and a solution using a Trie-based approach with bitwise manipulation is efficient.

inputFormat

The first line contains a single integer \(T\) --- the number of test cases. Each test case is described as follows:

  • The first number is an integer \(N\) --- the number of elements in the array.
  • Then, \(N\) integers follow which represent the elements of the array.

The input is provided via stdin and all numbers are separated by spaces and/or newline characters.

outputFormat

For each test case, output a single integer --- the maximum XOR sum of any subarray in that test case. Each result should be printed on its own line to stdout.

## sample
3
3 1 2 3
4 8 1 2 12
2 10 20
3

15 30

</p>