GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Sunday, 22 May 2022

[Solution] AND Sorting Codeforces Solution | Codeforces Problem Solution 2022

B. AND Sorting
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a permutation p of integers from 0 to n1 (each of them occurs exactly once). Initially, the permutation is not sorted (that is, pi>pi+1 for at least one 1in1).

The permutation is called X-sortable for some non-negative integer X if it is possible to sort the permutation by performing the operation below some finite number of times:

  • Choose two indices i and j (1i<jn) such that pi&pj=X.
  • Swap pi and pj.

Here & denotes the bitwise AND operation.

Solution Click Below:-  CLICK HERE

Input

The input consists of multiple test cases. The first line contains a single integer t (1t104)  — the number of test cases. Description of test cases follows.

The first line of each test case contains a single integer n (2n2105)  — the length of the permutation.

The second line of each test case contains n integers p1,p2,...,pn (0pin1, all pi are distinct)  — the elements of p. It is guaranteed that p is not sorted.

It is guaranteed that the sum of n over all cases does not exceed 2105.

Output

For each test case output a single integer — the maximum value of X such that p is X-sortable.

No comments:

Post a Comment