Bitwise swaps solution codechef
SOLUTION:- CLICK HERE
Given an arrayconsisting of integers , determine if you can sort this array by applying the following operation several times (possibly, zero):
- Pick a pair of indices bitwise AND operation. with and , and swap the values of and . Here, denotes the
For example, if, the two possible operations are and . cannot be performed because .
- The first line of input contains a single integer , denoting the number of test cases. The description of test cases follows.
- The first line of each test case contains a single integer .
- The second line contains space-separated integers
For each test case, output the answer on a new line —
YES if the given array can be sorted by repeatedly applying the given operation, and
You may print each character of the answer string in either uppercase or lowercase (for example, the strings
"YES" will all be treated as identical).
- for each
- The sum of over all test cases does not exceed
Subtask #1 (100 points): Original constraints
Sample Input 1
4 3 6 4 2 6 9 34 4 24 1 6 6 9 34 24 4 1 6 2 1 0
Sample Output 1
Yes Yes No No
Test case: can be sorted by applying the single operation .
Test case: can be sorted by applying the following operations in order: .
Test casesand : It can be shown that no sequence of operations will sort .