CF1227B.Box

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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

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

  • q1=p1q_1=p_1,
  • q2=max⁡(p1,p2)q_2=\max(p_1, p_2),
  • q3=max⁡(p1,p2,p3)q_3=\max(p_1, p_2,p_3),
  • ...
  • qn=max⁡(p1,p2,…,pn)q_n=\max(p_1, p_2,\dots,p_n).

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

排列 pp 是一个由 nn 个互不相同(唯一)的正整数构成的序列 p=[p1,p2,…,pn]p=[p_1, p_2, \dots, p_n],这些整数均在 11 到 nn 之间(含端点)。例如,以下序列均为排列:[3,4,1,2][3, 4, 1, 2]、[1][1]、[1,2][1, 2];而以下序列均不是排列:[0][0]、[1,2,1][1, 2, 1]、[2,3][2, 3]、[0,1,2][0, 1, 2]。

你需要打开一个上锁的箱子,而关键的钥匙就藏在箱内。要打开箱子,你必须输入一个秘密密码。该秘密密码是一个长度为 nn 的排列 pp。

你并不知道这个排列,仅知道该排列的前缀最大值数组 qq。形式化定义如下:

  • q1=p1q_1=p_1,
  • q2=max⁡(p1,p2)q_2=\max(p_1, p_2),
  • q3=max⁡(p1,p2,p3)q_3=\max(p_1, p_2,p_3),
  • …
  • qn=max⁡(p1,p2,…,pn)q_n=\max(p_1, p_2,\dots,p_n)。

你需要构造出任意一个满足条件的排列 pp(即:对该排列 pp 计算得到的前缀最大值数组 qq 恰好等于给定的数组)。

输入格式

The first line contains integer number tt (1≤t≤1041 \le t \le 10^4) — the number of test cases in the input. Then tt test cases follow.

The first line of a test case contains one integer nn (1≤n≤105)(1 \le n \le 10^{5}) — the number of elements in the secret code permutation pp.

The second line of a test case contains nn integers q1,q2,…,qnq_1, q_2, \dots, q_n (1≤qi≤n)(1 \le q_i \le n) — elements of the array qq for secret permutation. It is guaranteed that qi≤qi+1q_i \le q_{i+1} for all ii (1≤i<n1 \le i \lt n).

The sum of all values nn over all the test cases in the input doesn't exceed 10510^5.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 输入中测试用例的数量。随后是 tt 个测试用例。

每个测试用例的第一行包含一个整数 nn(1≤n≤1051 \le n \le 10^{5})—— 秘密排列 pp 中元素的个数。

每个测试用例的第二行包含 nn 个整数 q1,q2,…,qnq_1, q_2, \dots, q_n(1≤qi≤n1 \le q_i \le n)—— 对应秘密排列的数组 qq 的元素。保证对所有 ii(1≤i<n1 \le i \lt n)均有 qi≤qi+1q_i \le q_{i+1}。

输入中所有测试用例的 nn 值之和不超过 10510^5。

输出格式

For each test case, print:

  • If it's impossible to find such a permutation pp, print "-1" (without quotes).
  • Otherwise, print nn distinct integers p1,p2,…,pnp_1, p_2, \dots, p_n (1≤pi≤n1 \le p_i \le n). If there are multiple possible answers, you can print any of them.

对于每个测试用例,输出:

  • 如果无法找到满足条件的排列 pp,则输出 \-1(不带引号)。
  • 否则,输出 nn 个互不相同的整数 p1,p2,…,pnp_1, p_2, \dots, p_n(其中 1≤pi≤n1 \le p_i \le 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][1,3,4,5,2] is the only possible answer:

  • q1=p1=1q_{1} = p_{1} = 1;
  • q2=max⁡(p1,p2)=3q_{2} = \max(p_{1}, p_{2}) = 3;
  • q3=max⁡(p1,p2,p3)=4q_{3} = \max(p_{1}, p_{2}, p_{3}) = 4;
  • q4=max⁡(p1,p2,p3,p4)=5q_{4} = \max(p_{1}, p_{2}, p_{3}, p_{4}) = 5;
  • q5=max⁡(p1,p2,p3,p4,p5)=5q_{5} = \max(p_{1}, p_{2}, p_{3}, p_{4}, p_{5}) = 5.

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

在示例的第一个测试用例中,答案 [1,3,4,5,2][1,3,4,5,2] 是唯一可能的答案:

  • q1=p1=1q_{1} = p_{1} = 1;
  • q2=max⁡(p1,p2)=3q_{2} = \max(p_{1}, p_{2}) = 3;
  • q3=max⁡(p1,p2,p3)=4q_{3} = \max(p_{1}, p_{2}, p_{3}) = 4;
  • q4=max⁡(p1,p2,p3,p4)=5q_{4} = \max(p_{1}, p_{2}, p_{3}, p_{4}) = 5;
  • q5=max⁡(p1,p2,p3,p4,p5)=5q_{5} = \max(p_{1}, p_{2}, p_{3}, p_{4}, p_{5}) = 5。

可以证明,示例的第二个测试用例不存在可行解。

输入解题思路,AI测评打分。不知道怎么写?

首页