<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

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

      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();
      	}
      }
      
      posted @ 2019-11-24 23:02  qscqesze  閱讀(400)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 激情久久av一区二区三区| 欧美色丁香| 聂荣县| 亚洲av成人区国产精品| 亚洲av成人精品日韩一区| 伊人久久大香线蕉综合影院| 99riav国产精品视频| 激情伊人五月天久久综合| 日韩亚洲精品中文字幕| 中国亚洲女人69内射少妇| 亚洲aⅴ无码专区在线观看q| 国产成人精品一区二区三区| 久久96热在精品国产高清| 少妇高潮喷水正在播放| 国产精品久久久久久福利| 一个人在看www免费| 国产一区二区一卡二卡| 国产av一区二区麻豆熟女| 国产中文字幕精品免费| 国产成人久久777777| 亚洲中文字幕无码日韩精品| 亚洲精品一区二区动漫| 欧美性猛交xxxx黑人猛交| 无码专区 人妻系列 在线 | 国产精品一区二区AV| 起碰免费公开97在线视频| 精品久久精品午夜精品久久| 国产一级三级三级在线视| 亚洲日韩精品无码一区二区三区 | 国产91小视频在线观看| 亚洲欧美综合精品二区| 涟源市| 久久zyz资源站无码中文动漫| 国语精品自产拍在线观看网站 | 自偷自拍亚洲综合精品| 国产一区国产二区在线视频| 久久精品国产一区二区三| 亚洲深深色噜噜狠狠网站| 日韩精品久久不卡中文字幕 | 国产自国产自愉自愉免费24区 | 91久久偷偷做嫩草影院免费看|