B. Box

Permutation p is a sequence of integers p=[p1,p2,…,pn], consisting of n distinct (unique) positive integers between 1 and n, inclusive. For example, the following sequences are permutations: [3,4,1,2], [1], [1,2]. The following sequences are not permutations: [0], [1,2,1], [2,3], [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 p of length n.

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

q1=p1,

q2=max(p1,p2),

q3=max(p1,p2,p3),

...

qn=max(p1,p2,…,pn).

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

Input

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

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

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

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

Output

For each test case, print:

If it's impossible to find such a permutation p, print "-1" (without quotes).

Otherwise, print n distinct integers p1,p2,…,pn (1≤pi≤n). 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

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

q1=p1=1;

q2=max(p1,p2)=3;

q3=max(p1,p2,p3)=4;

q4=max(p1,p2,p3,p4)=5;

q5=max(p1,p2,p3,p4,p5)=5.

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

题意

现在给你前缀最大值是多少,让你还原这个排列,问你是否有解。

题解

给了你前缀最大值,我们现在如果发现前缀最大值变化了,那么这个位置肯定是这个最大值,否则就插入了一个小的数,那么我们插入最小的就好。

代码

#include<bits/stdc++.h>
using namespace std; vector<int>Q;
void solve(){
int n;scanf("%d",&n);
Q.clear();
vector<int> ans;
set<int>S;
for(int i=0;i<n;i++){
int x;scanf("%d",&x);
Q.push_back(x);
S.insert(i+1);
}
int mx = 0;
for(int i=0;i<n;i++){
if(Q[i]>mx){
if(S.count(Q[i])){
S.erase(Q[i]);
ans.push_back(Q[i]);
}else{
cout<<"-1"<<endl;
return;
}
mx = Q[i];
}else{
if(*S.begin()>mx){
cout<<"-1"<<endl;
return;
}else{
ans.push_back(*S.begin());
S.erase(S.begin());
}
}
}
for(int i=0;i<ans.size();i++){
cout<<ans[i]<<" ";
}
cout<<endl;
}
int main(){
int t;
scanf("%d",&t);
while(t--){
solve();
}
}

Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) B. Box 贪心的更多相关文章

  1. Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3

    A,有多个线段,求一条最短的线段长度,能过覆盖到所又线段,例如(2,4)和(5,6) 那么我们需要4 5连起来,长度为1,例如(2,10)(3,11),用(3,10) 思路:我们想一下如果题目说的是最 ...

  2. Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) F2. Wrong Answer on test 233 (Hard Version) dp 数学

    F2. Wrong Answer on test 233 (Hard Version) Your program fails again. This time it gets "Wrong ...

  3. Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) E. Arson In Berland Forest 二分 前缀和

    E. Arson In Berland Forest The Berland Forest can be represented as an infinite cell plane. Every ce ...

  4. Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) D2. Optimal Subsequences (Hard Version) 数据结构 贪心

    D2. Optimal Subsequences (Hard Version) This is the harder version of the problem. In this version, ...

  5. Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) C. Messy 构造

    C. Messy You are fed up with your messy room, so you decided to clean it up. Your room is a bracket ...

  6. Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) A. Math Problem 水题

    A. Math Problem Your math teacher gave you the following problem: There are n segments on the x-axis ...

  7. Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) C Messy

    //因为可以反转n次 所以可以得到任何可以构成的序列 #include<iostream> #include<string> #include<vector> us ...

  8. Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) B Box

    #include<bits/stdc++.h> using namespace std; ]; ]; int main() { int total; cin>>total; w ...

  9. Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) A Math Problem

    //只要从所有区间右端点的最小值覆盖到所有区间左端点的最大值即可 #include<iostream> using namespace std ; int x,y; int n; int ...

随机推荐

  1. js中cookie设置、获取与清除

    // 设置cookie setCookie (cname, cpwd, exdays) { var exdate = new Date()// 获取时间 exdate.setTime(exdate.g ...

  2. 记录/objc2/object_setClass做了啥

    inline Class objc_object::changeIsa(Class newCls) { // This is almost always true but there are // e ...

  3. 前端开发规范:4-JS

    ESLint 使用ESLint的standard规范来编写js代码 更多参考: https://github.com/standard/standard/blob/master/docs/README ...

  4. 使用Python轻松批量压缩图片

    在互联网,图片的大小对一个网站的响应速度有着明显的影响,因此在提供用户预览的时候,图片往往是使用压缩后的.如果一个网站图片较多,一张张压缩显然很浪费时间.那么接下来,我就跟大家分享一个批量压缩图片的方 ...

  5. 表单生成器(Form Builder)之伪造表单数据番外篇——指定范围随机时间

    为了伪造一些尽量真实的假数据,也真是够费劲的.上一篇笔记记录了一下获取一个随机车辆牌照,这篇笔记记录一下怎么获取一个随机时间.这篇就不说那么多废话了,直接上代码 // 获取指定范围的随机数 var g ...

  6. java 后端与前端Date类型与String类型互相转换(使用注解)

    后端返回的类型中,直接定义Date类型,加上此注解,直接将Date类型转成自定义的格式给前端 class TestDateOutput{ @JsonFormat(pattern = "yyy ...

  7. 新入手的Mac,该如何设置?

    如果您入手了一台Mac.设置Mac的过程直观且易于执行,但是如果您是新手,可能会遇到有一些小麻烦.没关系,本篇文章小编将帮助您设置Mac,让您像专业人士一样迅速运转您的Mac. 设置前提 在开始设置全 ...

  8. JS-for循环练习题

    1.大马驮2石粮食,中马驮1石粮食,两头小马驮一石粮食,要用100匹马,驮100石粮食,该如何调配? //驮100石粮食,大马需要50匹 for(var a=0;a<=50;a++){ //驮1 ...

  9. 20.never give up

  10. 安卓投屏助手(ARDC)最新版

    安卓投屏助手(B1493) 1.兼容Android 10: 2.增加灭屏投屏功能: 3.增加显示鼠标位置功能; 4.增加了虚拟NaviBar功能: 5.捐赠界面增加QQ支付,移除Paypal,感谢大家 ...