Editorial
Let be the sorted version of .
The allowed operation only swaps two odd indices or two even indices. Therefore, the multiset of values placed on odd indices and the multiset of values placed on even indices are invariant.
Conversely, if these two multisets are exactly the same as in the sorted sequence , then sorting is possible. Inside the odd indices, arbitrary permutations can be achieved by swaps, and the same holds for the even indices.
Thus, collect the values at odd indices of and , sort and compare them. Do the same for even indices. The answer is TAK if and only if both comparisons match.
The time complexity is .