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. html中的框架frameset和frame及iframe

    通过使用框架,你可以在同一个浏览器窗口中显示不止一个页面. 通过使用框架,你可以在同一个浏览器窗口中显示不止一个页面,简而言之,就是在一个窗口中显示多个页面. 每个页面称之为一个框架.并且每个框架独立 ...

  2. 小程序模板template使用介绍

    template(模板):是可以在wxml中引用的代码,就是在wxml中引用公用的wxml类型的代码,它的作用类似于组件,因此这里简单的说明下template与Component (组件)的区别. t ...

  3. Go Modules使用教程

    Go Modules 不完全教程 文章转载自公众号 Golang 成神之路 , 作者 L Go Modules 是 Golang 官方最近几个版本推出的原生的包管理方式,在此之前,社区也不乏多种包管理 ...

  4. sql server2017开启远程连接

    1.安装完SQL server2017之后,选择SQL 身份验证登录,可以先用windows身份验证登录把密码更改好了,然后服务器右键重新启动 ,再断开连接 ,选择SQL身份验证登录验证,关闭SQL ...

  5. 12.2新特性 使用DBCA duplicate创建物理备用数据库 (Doc ID 2283697.1)

    Creating a Physical Standby database using DBCA duplicate (Doc ID 2283697.1) APPLIES TO: Oracle Data ...

  6. 在IOS设备上POST提交form表单,后台接收不到值怎么办?

    原文:https://blog.csdn.net/xhaimail/article/details/90440029 最近在工作上遇到一个奇葩问题,在Android和Windows平台上做请求时参数都 ...

  7. verilog常见错误列表

    Error/Warning 来源:https://hdlbits.01xz.net/wiki/ 题目: 1.Quartus Warning 10235: Warning (): Verilog HDL ...

  8. SpringCloud中Feign的适配器的实现方案

    前言 最近在做微服务的项目,各个系统之间需要进行调用,然后用一个适配器来实现服务之间的feign调用,使用适配器进行统一管理. 实现方案 首先我们需要将服务的名称进行单独的配置,可以方便的进行切换和扩 ...

  9. 痞子衡嵌入式:开启NXP-MCUBootUtility工具的BEE/OTFAD加密功能 - image_enc

    软件v1.x仅支持BEE加密: 为了便于大家快速验证软件BEE加密功能,特将用于BEE加密的image_enc工具上传至百度网盘,仅用作个人学习用途,违者后果自负. -- 链接: https://pa ...

  10. Thinkphp <= 5.0.10 缓存getshell复现

    目录 Thinkphp <= 5.0.10 缓存getshell复现 0x01 poc 0x02 跟踪源码 0x03 审计思路 0x04 补丁 0x05 参考 Thinkphp <= 5. ...