CF BUDDY
← Problems·

1777F · Comfortably Numb

2400 · bitmasks, data structures, divide and conquer

Problem: You are given an array aa consisting of nn non-negative integers.

The numbness of a subarray al,al+1,,ara_l, a_{l+1}, \ldots, a_r (for arbitrary lrl \leq r) is defined as max(al,al+1,,ar)(alal+1ar),\max(a_l, a_{l+1}, \ldots, a_r) \oplus (a_l \oplus a_{l+1} \oplus \ldots \oplus a_r), where \oplus denotes the bitwise XOR operation.

Find the maximum numbness over all subarrays.

Input Format: Each test contains multiple test cases. The first line contains the number of test cases tt (1t10001 \le t \le 1000). The description of the test cases follows.

The first line of each test case contains a single integer nn (1n21051 \leq n \leq 2 \cdot 10^5).

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (0ai1090 \leq a_i \leq 10^9).

It is guaranteed that the sum of nn over all test cases does not exceed 21052 \cdot 10^5.

Output Format: For each test case, print one integer — the maximum numbness over all subarrays of the given array.

Note: For the first test case, for the subarray [3,4,5][3, 4, 5], its maximum value is 55. Hence, its numbness is 34553 \oplus 4 \oplus 5 \oplus 5 = 77. This is the maximum possible numbness in this array.

In the second test case the subarray [47,52][47, 52] provides the maximum numbness.

Sample Cases

Case 1

Input

2
5
1 2 3 4 5
3
10 47 52

Output

7
47

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback