#P10033. 「Cfz Round 3」Sum of Permutation
「Cfz Round 3」Sum of Permutation
Problem Description
Please note the special time limit of this problem.
You are given a permutation of .
You need to construct a sequence of length such that:
- Every element in sequence is a positive integer not greater than .
- There does not exist an ordered integer pair satisfying and .
Or report that there is no solution.
A permutation of means a sequence in which every positive integer not greater than appears exactly once.
Input Format
This problem has multiple test cases.
The first line contains an integer , indicating the number of test cases.
Then each test case is given as follows:
- The first line contains an integer .
- The second line contains integers, representing the given permutation .
Output Format
For each test case, output one line:
- If there exists a sequence that satisfies the conditions, output integers separated by spaces, representing the sequence you constructed.
- If no such sequence exists, output .
Any output that meets the requirements will be accepted.
4
3
3 2 1
2
1 2
5
4 2 1 5 3
7
5 7 3 1 2 4 6
1 3 3
-1
5 3 2 1 1
2 3 5 4 6 3 1
Hint
"Sample Explanation #1"
For the -st test case, both and are valid sequences .
For the -nd test case, it can be proven that no valid sequence exists.
For the -rd test case, besides , , , , etc. are all valid sequences .
Constraints
Let denote the sum of within a single test.
For all testdata, , , . It is guaranteed that is a permutation of .
You can get the score for this problem only if you pass all test points.
The input and output size is large, so please use fast I/O.
Translated by ChatGPT 5