#P1945E. Binary Search
Binary Search
Description
Anton got bored during the hike and wanted to solve something. He asked Kirill if he had any new problems, and of course, Kirill had one.
You are given a permutation of size , and a number that needs to be found. A permutation of length is an array consisting of distinct integers from to in arbitrary order. For example, is a permutation, but is not a permutation ( appears twice in the array), and is also not a permutation ( but there is in the array).
You decided that you are a cool programmer, so you will use an advanced algorithm for the search — binary search. However, you forgot that for binary search, the array must be sorted.
You did not give up and decided to apply this algorithm anyway, and in order to get the correct answer, you can perform the following operation no more than times before running the algorithm: choose the indices , () and swap the elements at positions and .
After that, the binary search is performed. At the beginning of the algorithm, two variables and are declared. Then the following loop is executed:
- If , end the loop
- If , assign , otherwise .
The goal is to rearrange the numbers in the permutation before the algorithm so that after the algorithm is executed, is equal to . It can be shown that operations are always sufficient.
Each test consists of multiple test cases. The first line contains a single integer () — the number of test cases. Then follow the descriptions of the test cases.
The first line of each test case contains two integers and () — the length of the permutation and the number to be found.
The second line contains the permutation separated by spaces ().
It is guaranteed that the sum of the values of for all test cases does not exceed .
For each test case, output an integer () on the first line — the number of operations performed by you. In the next lines, output integers , () separated by a space, indicating that you are swapping the elements at positions and .
Note that you do not need to minimize the number of operations.
Input
Each test consists of multiple test cases. The first line contains a single integer () — the number of test cases. Then follow the descriptions of the test cases.
The first line of each test case contains two integers and () — the length of the permutation and the number to be found.
The second line contains the permutation separated by spaces ().
It is guaranteed that the sum of the values of for all test cases does not exceed .
Output
For each test case, output an integer () on the first line — the number of operations performed by you. In the next lines, output integers , () separated by a space, indicating that you are swapping the elements at positions and .
Note that you do not need to minimize the number of operations.