Corrupted Sort
문제
Chloe wants to test her sorting skills. She has cards with distinct integers from to written on them. She asks her little brother Connor to first blindfold her and then arrange all cards in a row in some order. Positions of cards are numbered from to from left to right.
Chloe doesn't know the order of the cards, but she wants to sort them, so that the leftmost card has number and the rightmost card has number on it. Formally, for each she wants the card on position to have number on it. To achieve the goal, Chloe can ask Connor to do one or more operations.
Each operation can be denoted by two integers and (). Connor looks at the cards on positions and , and if the card on position has a bigger number than the card on position , he swaps them. Otherwise, he does nothing. Connor also tells Chloe if he swapped the cards or not.
To make the game more interesting, after every operations Connor chooses two distinct cards uniformly at random and swaps them without telling anything to Chloe.
If after some of Chloe's operations all cards become sorted, Chloe wins. Help Chloe to sort all cards using at most operations.
힌트
Initial card ordering in the example was (that is, the card on position had number on it, the card on position had number , and the card on position had number ).
예제
예제 1
3 SWAPPED STAYED WIN
1 2 1 3 2 3