#P16919. [JLCPC 2026] 古明地恋世界第一

    ID: 19237 远端评测题 1000ms 1024MiB 尝试: 0 已通过: 0 显示难度普及+/提高− 上传者: 标签>贪心吉林Special JudgeO2优化2026省赛/邀请赛

[JLCPC 2026] 古明地恋世界第一

Problem Description

Koishi picked up a positive integer sequence a=[a1,a2,⋯ ,an]a = [a_1, a_2, \cdots, a_n] of length nn on the road, where 1≤ai≤n1\le a_i\le n. Now Koishi computed the prefix maximum sequence b=[b1,b2,⋯ ,bn]b = [b_1, b_2, \cdots, b_n] of aa, where bib_i denotes the maximum among the first ii elements of aa, i.e.

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

After obtaining the two sequences, Koishi mixed them together: define a sequence cc of length 2n2n as c=[a1,a2,⋯ ,an,b1,b2,⋯ ,bn]c = [a_1, a_2, \cdots, a_n, b_1, b_2, \cdots, b_n], and then sorted cc in non-decreasing order.

Because Koishi is an unconscious girl, she lost the values of aa and bb, leaving only the sequence cc.

Because Koishi is an unconscious girl, she gave you the sequence cc—the cutest college student of the 21st century—hoping that you can find any valid sequence aa. There may be multiple valid sequences aa; in that case, you only need to output any one of them. There may also be no valid sequence aa at all; in that case, you need to report that there is no solution.

Input Format

The first line contains an integer TT, denoting the number of test cases. Then follow TT test cases, each described as follows:

  • The first line contains an integer nn, the length of sequence aa.
  • The second line contains a sequence cc of length 2×n2 \times n, where adjacent integers are separated by a single space. It is guaranteed that cc is non-decreasing, and 1≤ci≤n1\le c_i\le n.

It is guaranteed that 1≤∑n≤3×1051\le \sum n\le 3\times 10^5.

Output Format

For each test case:

  • If there is a solution, output a string Yes on the first line, and output nn integers [a1,a2,⋯ ,an][a_1, a_2, \cdots, a_n] on the second line, separated by single spaces, representing one valid sequence aa you found.
  • If there is no solution, output a single line with the string No.

Yes and No are case-insensitive. For example, Yes, YES, and yEs are all considered affirmative, while No, NO, and nO are all considered negative.

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
Yes
1 2 3
No
Yes
1 1 4 5 1 4
No
Yes
9 9 8 2 4 4 3 5 3

Hint

Translated by ChatGPT 5