#P9395. 橙垒球

    ID: 10289 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>洛谷原创Special JudgeO2优化洛谷月赛

橙垒球

Problem Description

Baseball really likes a problem called Mini Something · Suffix, and also greatly admires the author of that problem, so they made a similar problem.

Given a sequence a1,,ana_1,\ldots,a_n of length nn, construct a lexicographically maximum string ww of length nn such that:

  • Each character of ww is an integer from 11 to nn, and the order of characters is 11 as the smallest and nn as the largest.

  • For the prefix of ww with length ii, the length of its lexicographically maximum suffix is exactly aia_i.

Output such a ww, or report that there is no solution.

This problem contains multiple test cases in a single test point.

Input Format

The first line contains an integer TT, which is the number of test cases.

Then follow TT test cases. For each test case:

The first line contains an integer nn.

The second line contains nn integers a1,,ana_1,\ldots,a_n.

Output Format

For each test case:

If there is no solution, output one line with a single integer 1-1.

If there is a solution, output one line with nn integers, representing the string ww you constructed.

6
3
1 1 1
3
1 1 2
3
1 1 3
3
1 2 1
3
1 2 2
3
1 2 3

1 2 3
2 3 3
-1
2 2 3
-1
3 3 3

Hint

Sample Explanation

For the string 1,2,31,2,3, for each prefix, the length of its maximum suffix is exactly 1,1,11,1,1, and it is the lexicographically maximum string satisfying this condition.

For the string 2,3,32,3,3, for each prefix, the length of its maximum suffix is exactly 1,1,21,1,2, and it is the lexicographically maximum string satisfying this condition.

There does not exist a string such that for each prefix, the length of its maximum suffix is exactly 1,1,31,1,3.

For the string 2,2,32,2,3, for each prefix, the length of its maximum suffix is exactly 1,2,11,2,1, and it is the lexicographically maximum string satisfying this condition.

There does not exist a string such that for each prefix, the length of its maximum suffix is exactly 1,2,21,2,2.

For the string 3,3,33,3,3, for each prefix, the length of its maximum suffix is exactly 1,2,31,2,3, and it is the lexicographically maximum string satisfying this condition.


Scoring

The score of each test point equals the minimum score among all testdata within it. The score of a single testdata is determined as follows:

If your output format is wrong (i.e., it does not meet the output format requirements), you get no score.

Otherwise, if you correctly determine whether a solution exists (i.e., output 1-1 for unsolvable testdata, and output nn numbers in [1,n][1,n] for solvable testdata), you can get 20%20\% of the score.

On this basis, if the test point is unsolvable, or it is solvable and you output a valid solution (not necessarily the lexicographically maximum one), you can get an additional 30%30\% of the score.

On this basis, if the test point is unsolvable, or it is solvable and you output the lexicographically maximum solution, you can get an additional 50%50\% of the score.


Constraints

For all testdata: 1T100001\leq T\leq 10000, 1n4×1061 \le n \le 4 \times 10 ^ 6, n4×106\sum n\leq 4\times 10^6, 1aii1\leq a_i\leq i.

Subtask ID n\sum n\leq Special Property Score
Subtask 1\text{Subtask 1} 4×1064\times 10^6 Guaranteed no solution 11
Subtask 2\text{Subtask 2} 4×1054\times 10^5 Guaranteed solvable 2929
Subtask 3\text{Subtask 3} 4×1064\times 10^6 None 7070

Hint

Please use fast input/output methods.


Translated by ChatGPT 5