[Solution] AND Sorting Codeforces Solution | Codeforces Problem Solution 2022
You are given a permutation of integers from to (each of them occurs exactly once). Initially, the permutation is not sorted (that is, for at least one ).
The permutation is called -sortable for some non-negative integer if it is possible to sort the permutation by performing the operation below some finite number of times:
- Choose two indices and such that .
- Swap and .
Here denotes the bitwise AND operation.
The input consists of multiple test cases. The first line contains a single integer — the number of test cases. Description of test cases follows.
The first line of each test case contains a single integer — the length of the permutation.
The second line of each test case contains integers (, all are distinct) — the elements of . It is guaranteed that is not sorted.
It is guaranteed that the sum of over all cases does not exceed .
For each test case output a single integer — the maximum value of such that is -sortable.
No comments:
Post a Comment