CodeForces 1227B BOX

Description

\quad Permutation p p p is a a a sequence of integers p = [ p 1 , p 2 . . . p n ] p=\left[p_{1},p_{2}...p_{n}\right] p=[p1,p2...pn].consisting of n distinct (unique) positive integers between 1 1 1 and n n n, inclusive. For example, the following sequences are permutations: [ 3 , 4 , 1 , 2 ] \left[ 3,4,1,2\right] [3,4,1,2] [ 1 ] \left[1\right] [1] [ 1 , 2 ] \left[ 1,2\right] [1,2] The following sequences are not permutations: [ 0 ] \left[ 0\right] [0] [ 1 , 2.1 ] \left[ 1,2.1\right] [1,2.1] [ 2 , 3 ] \left[ 2,3\right] [2,3] [ 0 , 1 , 2 ] \left[ 0,1,2\right] [0,1,2].

\quad 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 a a permutation p p p of length n n n.

\quad You don’t know this permutation, you only know the array q q q of prefix maximums of this permutation. Formally:

  • q 1 = p 1 q_{1}=p_{1} q1=p1,
  • q 2 = m a x ( p 1 , p 2 ) q_{2}=max(p_{1},p_{2}) q2=max(p1,p2),
  • q 3 = m a x ( p 1 , p 2 , p 3 ) q_{3}=max(p_{1},p_{2},p_{3}) q3=max(p1,p2,p3),
  • q n = m a x ( p 1 , p 2 . . . p n ) q_{n}=max(p_{1},p_{2}...p_{n}) qn=max(p1,p2...pn).

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

Input

\quad The first line contains integer number t ( 1 ≤ t ≤ 1 0 4 ) t \left(1≤t≤10^{4} \right) t(1t104)— the number of test cases in the input. Then t test cases follow.

\quad The first line of a test case contains one integer n ( 1 ≤ n ≤ 2 ∗ 1 0 5 ) n\left(1≤n≤2*10^{5} \right) n(1n2105) — the number of elements in the secret code permutation p.

\quad The second line of a a a test case contains n n n integers q 1 , q 2 . . . q n ( 1 ≤ q i ≤ n ) q_{1},q_{2}...q_{n}\left(1≤q_{i}≤n \right) q1,q2...qn(1qin) — elements of the array q for secret permutation. It is guaranteed that qi≤qi+1 for all i ( 1 ≤ i ≤ n ) i \left(1≤i≤n \right) i(1in).

\quad The sum of all values n over all the test cases in the input doesn’t exceed 1 0 5 10^{5} 105.

Output

For each test case, print:

\quad If it’s impossible to find such a a a permutation p p p, print " − 1 " "-1" "1"(without quotes).
Otherwise, print n distinct integers p 1 , p 2 . . . p n ( 1 ≤ p i ≤ n ) p_{1},p_{2}...p_{n}\left(1≤p_{i}≤n \right) p1,p2...pn(1pin). If there are multiple possible answers, you can print any of them.

Example

input

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

output

1 3 4 5 2
-1
2 1
1

Note

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

  • q 1 = p 1 = 1 q_{1}=p_{1}=1 q1=p1=1,
  • q 2 = m a x ( p 1 , p 2 ) = 3 q_{2}=max(p_{1},p_{2})=3 q2=max(p1,p2)=3,
  • q 3 = m a x ( p 1 , p 2 , p 3 ) = 4 q_{3}=max(p_{1},p_{2},p_{3})=4 q3=max(p1,p2,p3)=4,
  • q 4 = m a x ( p 1 , p 2 , p 3 , p 4 ) = 5 q_{4}=max(p_{1},p_{2},p_{3},p_{4})=5 q4=max(p1,p2,p3,p4)=5
  • q 4 = m a x ( p 1 , p 2 , p 3 , p 4 , p 5 ) = 5 q_{4}=max(p_{1},p_{2},p_{3},p_{4},p_{5})=5 q4=max(p1,p2,p3,p4,p5)=5

\quad It can be proved that there are no answers for the second test case of the example.
给你一个数组q,让你判断有没有一个 序列p满足前i项最大值是给出序列对应位置的值(序列不能有重复的数)
自己当时写的很麻烦还错了一次,看了别人的思路学习了一种简单的把 a i a_{i} ai之前的数全压进去

AC代码:

#include <cstdio>
#include <vector>
#include <queue>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stack>
using namespace std;
#define sd(n) scanf("%d",&n)
#define sdd(n,m) scanf("%d%d",&n,&m)
#define sddd(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define pd(n) printf("%d\n", n)
#define pc(n) printf("%c", n)
#define pdd(n,m) printf("%d %d", n, m)
#define pld(n) printf("%lld\n", n)
#define pldd(n,m) printf("%lld %lld\n", n, m)
#define sld(n) scanf("%lld",&n)
#define sldd(n,m) scanf("%lld%lld",&n,&m)
#define slddd(n,m,k) scanf("%lld%lld%lld",&n,&m,&k)
#define sf(n) scanf("%lf",&n)
#define sc(n) scanf("%c",&n)
#define sff(n,m) scanf("%lf%lf",&n,&m)
#define sfff(n,m,k) scanf("%lf%lf%lf",&n,&m,&k)
#define ss(str) scanf("%s",str)
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,a,n) for(int i=n;i>=a;i--)
#define mem(a,n) memset(a, n, sizeof(a))
#define debug(x) cout << #x << ": " << x << endl
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mod(x) ((x)%MOD)
#define gcd(a,b) __gcd(a,b)
#define lowbit(x) (x&-x)
typedef pair<int,int> PII;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int MOD = 1e9 + 7;
const double eps = 1e-9;
const int maxn = 3e5 + 5;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const int inf = 0x3f3f3f3f;
inline int read()
{
    int ret = 0, sgn = 1;
    char ch = getchar();
    while(ch < '0' || ch > '9')
    {
        if(ch == '-')
            sgn = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
    {
        ret = ret*10 + ch - '0';
        ch = getchar();
    }
    return ret*sgn;
}
inline void Out(int a)    //Êä³öÍâ¹Ò
{
    if(a>9)
        Out(a/10);
    putchar(a%10+'0');
}

int qpow(int m, int k, int mod)
{
    int res = 1, t = m;
    while (k)
    {
        if (k&1)
            res = res * t % mod;
        t = t * t % mod;
        k >>= 1;
    }
    return res;
}

ll gcd(ll a,ll b)
{
    return b==0?a : gcd(b,a%b);
}

ll lcm(ll a,ll b)
{
    return a*b/gcd(a,b);
}
int n,m,t,cnt;
bool flag;
int a[100005];
stack<int> q;
int main()
{
    sd(t);
    while(t--)
    {
        sd(n);
        flag=0;
        rep(i,1,n)
        {
            cin>>a[i];
            if(a[i]<i)
                flag=1;
        }
        if(flag)
            printf("-1\n");
        else
        {
            cnt=0;
            rep(i,1,n)
            {
                while(cnt<a[i])
                {
                    q.push(++cnt);

                }
                printf("%d ",q.top());
                q.pop();
            }
            cout<<endl;
        }
    }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值