QOJ.ac

QOJ

実行時間制限: 1.0 s メモリ制限: 1024 MB 満点: 100 ハック可能 ✓

#18376. 恋恋天下第一

統計

恋恋在路上捡到了一个长度为 $n$ 的正整数序列 $a = [a_1, a_2, \dots, a_n]$,满足 $1 \le a_i \le n$。

她随后计算了前缀最大值序列 $b = [b_1, b_2, \dots, b_n]$,其中 $b_i$ 是 $a$ 的前 $i$ 个元素的最大值:

$$b_i = \max\{a_1, a_2, \dots, a_i\} = \max_{1 \le j \le i} \{a_j\}$$

在得到这两个序列后,恋恋将它们合并在一起,定义了一个长度为 $2n$ 的序列 $c = [a_1, a_2, \dots, a_n, b_1, b_2, \dots, b_n]$,并将 $c$ 按非降序(从小到大)排序。

作为无意识的少女,恋恋弄丢了 $a$ 和 $b$ 的值,只剩下了序列 $c$。

作为无意识的少女,恋恋把序列 $c$ 交给了你——21世纪最可爱的大学生——希望你能找到任意一个合法的序列 $a$。可能存在多个合法的序列,你只需要输出其中任意一个即可。也可能不存在合法的序列,在这种情况下,你应该报告无解。

输入格式

第一行包含一个整数 $T$ —— 测试用例的数量。接下来的 $T$ 个部分每个描述一个测试用例:

  • 第一行包含一个整数 $n$ —— 序列 $a$ 的长度。
  • 第二行包含一个长度为 $2 \times n$ 的序列 $c$,相邻整数之间用空格分隔。保证 $c$ 是非降序的,且 $1 \le c_i \le n$。

保证 $1 \le \sum n \le 3 \times 10^5$。

输出格式

对于每个测试用例:

  • 如果存在解,第一行输出 "Yes",第二行输出 $n$ 个整数 $[a_1, a_2, \dots, a_n]$,用空格分隔。
  • 如果不存在解,在单行中输出 "No"。

"Yes" 和 "No" 是不区分大小写的。例如,"Yes"、"YES"、"yEs" 都会被接受为肯定回答,而 "No"、"NO"、"nO" 都会被接受为否定回答。

样例

输入样例 1

5
3
1 1 2 2 3 3
3
1 1 1 1 2 3
6
1 1 1 1 1 4 4 4 5 5 5 5
5
1 1 1 2 3 4 5 5 5 5
9
2 3 3 4 4 5 8 9 9 9 9 9 9 9 9 9 9 9

输出样例 1

Yes
1 2 3
No
Yes
1 1 4 5 1 4
No
Yes
9 9 8 2 4 4 3 5 3

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.