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();
}
}

最新文章

  1. eclipse 快捷键Alt+/ 不能补充syso
  2. web工程 所需是jar包总结
  3. java---相亲练习
  4. c语言宏定义
  5. Spring中BeanPostProcessor
  6. oracle 过程函数,包的区别和联系
  7. SPOJ694 -- DISUBSTR 后缀树组求不相同的子串的个数
  8. 持续集成环境Jenkins的搭建和使用
  9. python_day06(ip代理池)
  10. 「mysql优化专题」主从复制面试宝典!面试官都没你懂得多!(11)
  11. jvm经典文章整理
  12. Java语法细节 - synchronized和volatile
  13. Jenkins结合.net平台综合之完整示例项目
  14. go使用rpc
  15. 【逆向工具】IDA使用1-VS2015版本debug查找Main函数,加载符号文件
  16. Qt读取TXT文件时,GBK与UTF-8编码判断
  17. centos redis5 安装 和 基本配置
  18. 使用Zxing开发Air版二维码扫描工具
  19. 「电脑应用」在mac上使用aria2
  20. Kali Linux安装SSH Server

热门文章

  1. Linux tree
  2. springBoot-eclipse搭建第一个项目
  3. js对象数组中的某属性值 拼接成字符串
  4. 编译出错:must be index or base register
  5. nginx基础(1)
  6. http并发访问模型(2)
  7. dom元素的tabindex属性介绍及在vue项目中的应用
  8. echarts 在 vue-awesome-swiper中无法点击
  9. UNIX系统编程知识点总结——思维导图
  10. 通过jgit一次性升级fastjson版本