Swap Sort

All submissions for this problem are available.
You are given a permutation of $n$ $a_1,a_2,...a_n$. You will also be given another integer $x$ between $1$ and $n$. In one move, you can swap the element $x$ with an element at an odd number of places to the left or right of it. For example, if $x$ is at position $i$, then you can swap it with $a_{i+1},a_{i+3},...$ and $a_{i1},a_{i3},...$ Your task is to sort the array in at most $10n$ moves or determine that it is impossible to sort the array ###Input:  First line will contain $T$, number of testcases. Then the testcases follow.  Each testcase contains two lines of input.  The first line contains two integers $n$ and $x$.  The second line contains $n$ space separated numbers $a_1,a_2,...a_n$ ###Output:  For each test case, output in the first line "YES" if it is possible to sort the array otherwise "NO."  If it is possible to sort the array, then in the next line output the number of moves $m$.  Then output $m$ lines, consisting of two indexes $i$ and $j$ to be swapped. (Note that either $i$ or $j$ should be the index of $x$. ###Constraints  $1 \leq T \leq 1000$  $1 \leq n \leq 10^5$  $1 \leq a_i \leq n$  $1 \leq x \leq n$  Sum of $n$ over all testcases is less than $10^5$ ###Sample Input: 2 3 2 2 1 3 3 3 2 1 3 ###Sample Output: YES 1 1 2 NO ###EXPLANATION: In the first test case, swapping 2 with 1 will sort the array. It is not possible to sort the array in the second test case.Author:  theanshul 
Tags  theanshul 
Date Added:  10022020 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, SQL, kotlin, PERL6, TEXT, CPP17, SCM chicken, PYP3, CLOJ, R, COB, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 