题目描述
You are given an array A of length N.
Find the maximum length of any subarray of A, such that, the [bitwise OR] of all the elements of the subarray is equal to the [bitwise OR] of the remaining elements of the array.
Report -1 if no such subarray exists.
Note:
A subarray is formed by deleting some (possibly zero) elements from the beginning of the array and some (possibly zero) elements from the end of the array.
The bitwise OR of an empty array is considered to be 0.
------ Input Format ------
- The first line of input contains a single integer T, denoting the number of test cases.
- Each test case consists of two lines of input.
- The first line of each test case contains an integer N — the length of the array A.
- The second line of each test case contains $N space-separated integers A_{1},A_{2},\ldots,A_{N}$ representing the array A.
------ Output Format ------
For each test case, output on a new line, the length of longest subarray such that the bitwise OR of all elements of the subarray is equal to the bitwise OR of the remaining elements of the array, or output -1 if no such subarray exists.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 5 \cdot 10^{5}$
$1 ≤ A_{i} < 2^{30}$
- The sum of $N$ over all test cases won't exceed $5 \cdot 10^{5}$.
----- Sample Input 1 ------
3
3
1 2 4
3
1 3 2
4
2 3 4 7
----- Sample Output 1 ------
-1
1
3
----- explanation 1 ------
Test case $1$: For no subarray of $A$, the bitwise OR of the elements of the subarray equals the bitwise OR of the remaining elements.
Test case $2$: Consider the subarray $[3]$ having length $1$. The bitwise OR of the subarray is $3$ and the bitwise OR of the remaining elements of the array is $1 | 2 = 3$. Thus, the bitwise OR of all elements of the subarray is equal to the bitwise OR of the remaining elements of the array.
Test case $3$: Consider the subarray $[2, 3, 4]$ having length $3$. The bitwise OR of the subarray is $2|3|4 = 7$ and the bitwise OR of the remaining elements of the array is $7$. Thus, the bitwise OR of all elements of the subarray is equal to the bitwise OR of the remaining elements of the array.
输入格式
见题面
输出格式
见题面