B. Box

B. Box

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Permutation pp is a sequence of integers p=[p1,p2,…,pn]p=[p1,p2,…,pn], consisting of nn distinct (unique) positive integers between 11 and nn, inclusive. For example, the following sequences are permutations: [3,4,1,2][3,4,1,2], [1][1], [1,2][1,2]. The following sequences are not permutations: [0][0], [1,2,1][1,2,1], [2,3][2,3], [0,1,2][0,1,2].

The important key is in the locked box that you need to open. To open the box you need to enter secret code. Secret code is a permutation pp of length nn.

You don't know this permutation, you only know the array qq of prefix maximums of this permutation. Formally:

  • q1=p1q1=p1,
  • q2=max(p1,p2)q2=max(p1,p2),
  • q3=max(p1,p2,p3)q3=max(p1,p2,p3),
  • ...
  • qn=max(p1,p2,…,pn)qn=max(p1,p2,…,pn).

You want to construct any possible suitable permutation (i.e. any such permutation, that calculated qq for this permutation is equal to the given array).

Input

The first line contains integer number tt (1≤t≤1041≤t≤104) — the number of test cases in the input. Then tt test cases follow.

The first line of a test case contains one integer nn (1≤n≤105)(1≤n≤105) — the number of elements in the secret code permutation pp.

The second line of a test case contains nn integers q1,q2,…,qnq1,q2,…,qn (1≤qi≤n)(1≤qi≤n) — elements of the array qq for secret permutation. It is guaranteed that qi≤qi+1qi≤qi+1 for all ii (1≤i<n1≤i<n).

The sum of all values nn over all the test cases in the input doesn't exceed 105105.

Output

For each test case, print:

  • If it's impossible to find such a permutation pp, print "-1" (without quotes).
  • Otherwise, print nn distinct integers p1,p2,…,pnp1,p2,…,pn (1≤pi≤n1≤pi≤n). If there are multiple possible answers, you can print any of them.

Example

input

Copy

4
5
1 3 4 5 5
4
1 1 3 4
2
2 2
1
1

output

Copy

1 3 4 5 2 
-1
2 1 
1 

Note

In the first test case of the example answer [1,3,4,5,2][1,3,4,5,2] is the only possible answer:

  • q1=p1=1q1=p1=1;
  • q2=max(p1,p2)=3q2=max(p1,p2)=3;
  • q3=max(p1,p2,p3)=4q3=max(p1,p2,p3)=4;
  • q4=max(p1,p2,p3,p4)=5q4=max(p1,p2,p3,p4)=5;
  • q5=max(p1,p2,p3,p4,p5)=5q5=max(p1,p2,p3,p4,p5)=5.

It can be proved that there are no answers for the second test case of the example.

\=========================================================================

模拟一下,放个队列即可,每当a值不等于上一个a值,那就说明了这个位置已经确定,一旦我们遇到一个确定位置,就把上一个位置到本位置之间的数字全部加入队列,这就是小于本位置的全部可能,当该取出数字的时候队列为空则是无解

# include <stdio.h>
#include<iostream>
# include<cstring>
# include<vector>
# include<queue>
# include<algorithm>
using namespace std;
typedef long long int ll;

int a[100000+10];
int ans[100000+10];
queue<int>q;
vector<int>v;

int main()
{

    int t;

    cin>>t;

    while(t--)
    {
        int n;

        cin>>n;


        while(!q.empty())
            q.pop();
        v.clear();

        for(int i=1; i<=n; i++)
        {
            cin>>a[i];

            ans[i]=0;

            if(a[i]!=a[i-1])
            {
                
                v.push_back(a[i]);

                ans[i]=a[i];
            }
        }

        int now=0;
        int last=1,flag=0;

        for(int i=1; i<=n; i++)
        {
            if(ans[i])
            {
                for(int j=last;j<v[now];j++)
                    q.push(j);


                    last=v[now]+1;

                    now++;

            }
            else
            {
                if(q.empty())
                {
                    flag=1;
                    break;
                }
                else
                {
                    ans[i]=q.front();
                    q.pop();
                }
            }
        }

        if(flag)
        {
            cout<<-1<<endl;

            continue;
        }

        for(int i=1;i<=n;i++)
        {
            cout<<ans[i]<<" ";
        }



        cout<<endl;
    }

    return  0;
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

秦三码

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值