QOJ.ac

QOJ

Time Limit: 3 s Memory Limit: 256 MB Total points: 100

#497. 评委问题

Statistics

Flatland 大学竞赛的评委们准备了一套非常棒的题目。但在比赛当天早上,他们发现计算机病毒摧毁了其中一道题的输入文件。现在他们急需恢复这些文件,并决定向你寻求帮助。给定“前缀覆盖”问题的答案,你需要恢复输入文件。

该问题的定义如下:考虑一个整数数组 $A = \langle a_1, a_2, \dots, a_n \rangle$。如果对于 $1$ 到 $n$ 之间的每个 $i$,都能在 $A$ 中找到一个等于 $a_i$ 的子数组,则称数组 $B = \langle b_1, b_2, \dots, b_m \rangle$ 覆盖了数组 $A$。例如,$A = \langle 1, 2, 1, 2, 1, 1, 2, 1 \rangle$ 可以被 $B = \langle 1, 2, 1 \rangle$ 覆盖。覆盖数组 $A$ 的最小长度 $m$ 称为 $A$ 的最小覆盖数,记作 $mc(A)$。在上面的例子中,$mc(\langle 1, 2, 1, 2, 1, 1, 2, 1 \rangle) = 3$。

给定 $A$ 的前缀覆盖数组 $P = \langle p_1, p_2, \dots, p_n \rangle$,这是一个由 $A$ 的各前缀的最小覆盖数组成的数组,即 $p_i = mc(\langle a_1, a_2, \dots, a_i \rangle)$。在上面的例子中,$P = \langle 1, 2, 3, 2, 3, 6, 7, 3 \rangle$。

评委们想让参赛队伍根据给定的数组求出前缀覆盖数组。现在你需要解决逆问题:给定数组 $P$,求出某个以 $P$ 为前缀覆盖数组的数组 $A$。

输入格式

输入文件包含多个测试用例。 每个测试用例的第一行包含 $n$ ($1 \le n \le 5 \cdot 10^5$)。第二行包含 $n$ 个整数 $p_i$ ($1 \le p_i \le i$)。 最后一个测试用例后跟一行包含零的行,该行不应被处理。 所有测试用例中 $n$ 的总和不超过 $5 \cdot 10^5$。

输出格式

对于每个测试用例,如果存在数组 $A$ 使得 $P$ 是其前缀覆盖数组,则输出 “Yes”。在这种情况下,下一行必须包含 $n$ 个范围在 $1$ 到 $n$ 之间的整数,即数组 $A$ 的元素。如果不存在这样的数组,则输出 “No”。

样例

样例输入 1

8
1 2 3 2 3 6 7 3
5
1 1 1 1 1
3
1 2 2
7
1 2 3 4 5 6 7
0

样例输出 1

Yes
1 2 1 2 1 1 2 1
Yes
1 1 1 1 1
No
Yes
1 2 3 4 5 6 7

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.