QOJ.ac

QOJ

حد الوقت: 1 s حد الذاكرة: 64 MB مجموع النقاط: 100

#6476. 密室逃脱

الإحصائيات

众所周知,密室逃脱游戏非常流行,因为它们能让你扮演电子游戏英雄的角色。其中一个密室有这样一个谜题:你知道储物柜的密码是一个长度为 $N$ 的排列。长度为 $N$ 的排列是指一个由 $N$ 个不同的正整数组成的序列,其值均不超过 $N$。你得到了关于密码的以下提示:以位置 $i$ 开头的最长上升子序列的长度等于 $A_i$。因此,你需要利用这些值找出密码。由于可能存在多个满足条件的排列,你希望找到字典序最小的那一个。如果存在一个索引 $i$,使得 $P_i < Q_i$ 且对于所有 $j < i$ 都有 $P_j = Q_j$,则称排列 $P$ 的字典序小于排列 $Q$。题目保证至少存在一个满足上述约束的排列。

你能打开这扇门吗?

输入格式

第一行包含一个整数 $N$ ($1 \le N \le 10^5$)。 第二行包含 $N$ 个空格分隔的整数 $A_i$ ($1 \le A_i \le N$)。 题目保证至少存在一个可能的排列。

输出格式

在一行中输出满足所有条件的字典序最小的排列。

样例

输入 1

4
1 2 2 1

输出 1

4 2 1 3

输入 2

1
1

输出 2

1

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.