Xor With Smallest Element
Problem
Chef has an array of length and an integer .
In one operation, Chef does the following:
- Find the smallest element in the current array. Let this be .
- Next, pick any one index such that
- Finally, replace with
Here denotes the bitwise XOR operation.
For example, if and , then in one move Chef can turn the array into either or .
Chef performs this operation exactly times. Let be final array obtained.
Output the array in sorted order. Note that under this restriction, the output is unique.
Input Format
- The first line of input will contain a single integer , denoting the number of test cases.
- Each test case consists of two lines of input.
- The first line of each test case contains three space-separated integers , , and .
- The second line contains space-separated integers denoting the array .
Output Format
For each test case, output array in sorted order.
Constraints
- The sum of over all test cases won't exceed .
Sample 1:
Input
Output
3 1 6 99 9 3 7 44 1 2 3 5 20 6 5 10 15 20 25
15 3 5 6 5 20 25 27 30
Explanation:
Test case : The array is initially . Since there is only one element, it will be modified in each step. So,
- After the first operation, the array is (since )
- After the second operation, the array is (since )
- Continuing the above, it can be verified that after steps, the array is .
Test case : The sequence of steps is as follows:
- Initially, the array is
- After operation , it is
- After operation , it is
- After operation , it is
- After operation , it is
- After operation , it is
- After operation , it is
Remember to print the output in sorted order.
Comments
Post a Comment