CF1768C.Elemental Decompress

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given an array aa of nn integers.

Find two permutations†^\dagger pp and qq of length nn such that max⁡(pi,qi)=ai\max(p_i,q_i)=a_i for all 1≤i≤n1 \leq i \leq n or report that such pp and qq do not exist.

†^\dagger A permutation of length nn is an array consisting of nn distinct integers from 11 to nn in arbitrary order. For example, [2,3,1,5,4][2,3,1,5,4] is a permutation, but [1,2,2][1,2,2] is not a permutation (22 appears twice in the array), and [1,3,4][1,3,4] is also not a permutation (n=3n=3 but there is 44 in the array).

给你一个包含 nn 个整数的数组 aa。

请找出两个长度为 nn 的排列†^\dagger pp 和 qq,使得对所有 1≤i≤n1 \leq i \leq n 均满足 max⁡(pi,qi)=ai\max(p_i,q_i)=a_i;若不存在这样的 pp 和 qq,则报告无解。

†^\dagger 长度为 nn 的排列是指由 11 到 nn 中互不相同的 nn 个整数组成的数组(顺序任意)。例如,[2,3,1,5,4][2,3,1,5,4] 是一个排列,而 [1,2,2][1,2,2] 不是排列(数字 22 在数组中出现了两次),[1,3,4][1,3,4] 也不是排列(此时 n=3n=3,但数组中出现了 44)。

输入格式

The first line contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases. The description of test cases follows.

The first line of each test case contains a single integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5).

The second line of each test case contains nn integers a1,a2,…,ana_1,a_2,\ldots,a_n (1≤ai≤n1 \leq a_i \leq n) — the array aa.

It is guaranteed that the total sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5)。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1,a_2,\ldots,a_n(1≤ai≤n1 \leq a_i \leq n)—— 即数组 aa。

保证所有测试用例的 nn 值之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, if there do not exist pp and qq that satisfy the conditions, output "NO" (without quotes).

Otherwise, output "YES" (without quotes) and then output 22 lines. The first line should contain nn integers p1,p2,…,pnp_1,p_2,\ldots,p_n and the second line should contain nn integers q1,q2,…,qnq_1,q_2,\ldots,q_n.

If there are multiple solutions, you may output any of them.

You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).

对于每个测试用例,若不存在满足条件的 pp 和 qq,则输出 "NO"(不带引号)。

否则,先输出 "YES"(不带引号),然后输出 22 行:第一行包含 nn 个整数 p1,p2,…,pnp_1,p_2,\ldots,p_n,第二行包含 nn 个整数 q1,q2,…,qnq_1,q_2,\ldots,q_n。

若存在多个解,可输出其中任意一个。

"YES" 和 "NO" 的大小写不限(例如,字符串 "yEs"、"yes" 和 "Yes" 均被视为肯定回答)。

输入输出样例

  • 输入#1

    3
    1
    1
    5
    5 3 4 2 5
    2
    1 1

    输出#1

    YES
    1 
    1 
    YES
    1 3 4 2 5 
    5 2 3 1 4 
    NO

说明/提示

In the first test case, p=q=[1]p=q=[1]. It is correct since a1=max(p1,q1)=1a_1 = max(p_1,q_1) = 1.

In the second test case, p=[1,3,4,2,5]p=[1,3,4,2,5] and q=[5,2,3,1,4]q=[5,2,3,1,4]. It is correct since:

  • a1=max⁡(p1,q1)=max⁡(1,5)=5a_1 = \max(p_1, q_1) = \max(1, 5) = 5,
  • a2=max⁡(p2,q2)=max⁡(3,2)=3a_2 = \max(p_2, q_2) = \max(3, 2) = 3,
  • a3=max⁡(p3,q3)=max⁡(4,3)=4a_3 = \max(p_3, q_3) = \max(4, 3) = 4,
  • a4=max⁡(p4,q4)=max⁡(2,1)=2a_4 = \max(p_4, q_4) = \max(2, 1) = 2,
  • a5=max⁡(p5,q5)=max⁡(5,4)=5a_5 = \max(p_5, q_5) = \max(5, 4) = 5.

In the third test case, one can show that no such pp and qq exist.

在第一个测试用例中,p=q=[1]p=q=[1]。这是正确的,因为 a1=max⁡(p1,q1)=1a_1 = \max(p_1,q_1) = 1。

在第二个测试用例中,p=[1,3,4,2,5]p=[1,3,4,2,5] 且 q=[5,2,3,1,4]q=[5,2,3,1,4]。这是正确的,因为:

  • a1=max⁡(p1,q1)=max⁡(1,5)=5a_1 = \max(p_1, q_1) = \max(1, 5) = 5,
  • a2=max⁡(p2,q2)=max⁡(3,2)=3a_2 = \max(p_2, q_2) = \max(3, 2) = 3,
  • a3=max⁡(p3,q3)=max⁡(4,3)=4a_3 = \max(p_3, q_3) = \max(4, 3) = 4,
  • a4=max⁡(p4,q4)=max⁡(2,1)=2a_4 = \max(p_4, q_4) = \max(2, 1) = 2,
  • a5=max⁡(p5,q5)=max⁡(5,4)=5a_5 = \max(p_5, q_5) = \max(5, 4) = 5。

在第三个测试用例中,可以证明不存在满足条件的 pp 和 qq。

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

首页