题目描述
You are given an array B containing N integers, each of which is either -1 or a non-negative integer. Construct any integer array A of length N such that:
0 ≤ A_{i} ≤ 10^{9} for every 1 ≤ i ≤ N
If B_{i} ≥ 0, A must satisfy $mex(A_{1}, A_{2}, \ldots, A_{i}) = B_{i}$
Otherwise, B_{i} = -1, which means there is no constraint on $mex(A_{1}, A_{2}, \ldots, A_{i})$
If there does not exist any array satisfying the constraints, print -1 instead.
Note: The mex of a set of non-negative integers is the smallest non-negative integer that does not belong to it. For example, mex(1, 2, 3) = 0, mex(0, 2, 4, 1) = 3, and mex(0, 0, 0) = 1.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of testcases. The description of T testcases follows.
- The first line of each testcase contains a single integer N.
- The second line of each testcase contains $N space-separated integers B_{1}, B_{2}, \ldots, B_{N}$.
------ Output Format ------
For each testcase, output the required answer on a new line: -1 if no valid array exists, or N space-separated integers denoting the elements of any valid array A. The elements of A must satisfy 0 ≤ A_{i} ≤ 10^{9}.
------ Constraints ------
$1 ≤ T ≤ 10^{4}$
$1 ≤ N ≤ 10^{5}$
$-1 ≤ B_{i} ≤ 10^{5}$
- The sum of $N$ across all testcases won't exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
2
7
0 -1 2 -1 5 -1 -1
3
2 -1 -1
----- Sample Output 1 ------
1 3 0 4 2 6 5
-1
----- explanation 1 ------
Test case $1$: We have $A = [1, 3, 0, 4, 2, 6, 5]$. Let $C_{i} = mex(A_{1}, A_{2}, \ldots, A_{i})$. Then, it can be seen that $C = [0, 0, 2, 2, 5, 5, 7]$, which matches $B$ at all positions where $B_{i} ≥ 0$.
Test case $2$: It can be shown that no array $A$ exists that satisfies the given constraints.
输入格式
见题面
输出格式
见题面