CF1227B.Box
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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).
排列 p 是一个由 n 个互不相同(唯一)的正整数构成的序列 p=[p1,p2,…,pn],这些整数均在 1 到 n 之间(含端点)。例如,以下序列均为排列:[3,4,1,2]、[1]、[1,2];而以下序列均不是排列:[0]、[1,2,1]、[2,3]、[0,1,2]。
你需要打开一个上锁的箱子,而关键的钥匙就藏在箱内。要打开箱子,你必须输入一个秘密密码。该秘密密码是一个长度为 n 的排列 p。
你并不知道这个排列,仅知道该排列的前缀最大值数组 q。形式化定义如下:
- q1=p1,
- q2=max(p1,p2),
- q3=max(p1,p2,p3),
- …
- qn=max(p1,p2,…,pn)。
你需要构造出任意一个满足条件的排列 p(即:对该排列 p 计算得到的前缀最大值数组 q 恰好等于给定的数组)。
输入格式
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.
第一行包含一个整数 t(1≤t≤104)—— 输入中测试用例的数量。随后是 t 个测试用例。
每个测试用例的第一行包含一个整数 n(1≤n≤105)—— 秘密排列 p 中元素的个数。
每个测试用例的第二行包含 n 个整数 q1,q2,…,qn(1≤qi≤n)—— 对应秘密排列的数组 q 的元素。保证对所有 i(1≤i<n)均有 qi≤qi+1。
输入中所有测试用例的 n 值之和不超过 105。
输出格式
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.
对于每个测试用例,输出:
- 如果无法找到满足条件的排列 p,则输出
\-1(不带引号)。 - 否则,输出 n 个互不相同的整数 p1,p2,…,pn(其中 1≤pi≤n)。如果存在多个可能的答案,输出任意一个即可。
输入输出样例
输入#1
4 5 1 3 4 5 5 4 1 1 3 4 2 2 2 1 1
输出#1
1 3 4 5 2 -1 2 1 1
说明/提示
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.
在示例的第一个测试用例中,答案 [1,3,4,5,2] 是唯一可能的答案:
- 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。
可以证明,示例的第二个测试用例不存在可行解。
输入解题思路,AI测评打分。不知道怎么写?