[Solution] Mystic Permutation Codeforces Solution | Codeforces Problem Solution 2022
Monocarp is a little boy who lives in Byteland and he loves programming.
Recently, he found a permutation of length . He has to come up with a mystic permutation. It has to be a new permutation such that it differs from the old one in each position.
More formally, if the old permutation is and the new one is it must hold that
Monocarp is afraid of lexicographically large permutations. Can you please help him to find the lexicographically minimal mystic permutation?
There are several test cases in the input data. The first line contains a single integer
() — the number of test cases. This is followed by the test cases description.
The first line of each test case contains a positive integer () — the length of the permutation.
The second line of each test case contains distinct positive integers (). It's guaranteed that is a permutation, i. e. for all .
It is guaranteed that the sum of does not exceed over all test cases.
For each test case, output positive integers — the lexicographically minimal mystic permutations. If such a permutation does not exist, output instead.
No comments:
Post a Comment