QOJ.ac

QOJ

时间限制: 5 s 内存限制: 1024 MB 总分: 100

#4720. 排列恢复

统计

Ghiţă 非常热衷于竞技编程。他最喜欢的活动是研究排列组合,并与他的妻子 Ana 共度时光。在他们结婚 10 周年纪念日时,Ana 送给他一个非常漂亮的排列,因为她知道这是 Ghiţă 能收到的最好的礼物。令 $P_j$ 为该排列的第 $j$ 个元素,其中 $1 \le j \le N$。

Ghiţă 对这份礼物感到非常兴奋,以至于他开始计算每个 $i$($1 \le i \le N$)对应的数值 $Q_i$。$Q_i$ 定义为他在其排列的前缀长度为 $i$ 的部分中能找到的递增子序列的数量。

更正式地说,对于每个 $1 \le i \le N$,$Q_i$ 是满足 $1 \le j_1 < j_2 < \dots < j_{k-1} < j_k \le i$ 且 $P_{j_1} < P_{j_2} < \dots < P_{j_k}$ 的整数数组 $j_1, j_2, \dots, j_k$ 的数量。

他认为 $Q$ 虽然不是一个排列,但也非常不错。这就是为什么他把它保存在排列 $P$ 附近。

一切都很顺利,直到 Lică Sămădăul 出现。他想利用 Ghiţă 的监控系统进行不正当目的,而 Ghiţă 是一个正直的人,没有帮助他。Lică Sămădăul 被 Ghiţă 的回答激怒了,雇佣了 Buză Spartă 来帮助他窃取 Ghiţă 最宝贵的资产:他的排列和妻子。他确实这么做了。

第二天,Ghiţă 发现 $P$ 不见了,现在 Ghiţă 恢复排列的唯一方法是使用他仍然拥有的数组 $Q$。你可以猜到,你的工作是帮助 Ghiţă 根据提供的数组 $Q$ 恢复数组 $P$。

输入格式

输入的第一行包含 $N$,即排列的长度。第二行包含由空格分隔的 $Q_1, Q_2, \dots, Q_n$。

输出格式

在输出的第一行(也是唯一一行),你应该打印代表被窃排列的数组 $P$。

数据范围

  • 保证存在唯一可能的答案(只有一个 $P$ 对应给定的 $Q$)。
  • $N \le 70\,000$
  • 输入大小小于 $111\text{ MB}$。
  • 我们建议你独立检查程序读取部分的运行时间和内存使用情况,以确保程序的最终效率低下不是由这部分引起的,因为读取输入并不旨在成为解决此任务的障碍。

子任务

子任务 限制 $T=Q(N)$ 的位数 最大输入大小 分值
1 $N \le 9$ - - 10 分
2 $N \le 400$ $T \le 18$ - 15 分
3 $N \le 700$ - - 18 分
4 $N \le 40\,000$ $T \le 171$ $4.5\text{ MB}$ 17 分
5 $N \le 70\,000$ $T \le 258$ $10\text{ MB}$ 11 分
6 $N \le 70\,000$ $T \le 314$ $16\text{ MB}$ 7 分
7 $N \le 70\,000$ - $85\text{ MB}$ 16 分
8 $N \le 70\,000$ - $111\text{ MB}$ 6 分

样例

样例输入 1

4
1 2 5 6

样例输出 1

3 2 4 1

样例输入 2

6
1 3 5 9 11 21

样例输出 2

1 6 3 4 2 5

说明

在第一个样例中,$N = 4$ 且 $P = \{3, 2, 4, 1\}$ $Q_1 = 1$,因为 $\{3\}$ 是 $\{3\}$ 的唯一递增子序列 $Q_2 = 2$,因为 $\{3\}$ 和 $\{2\}$ 是 $\{3, 2\}$ 的唯一递增子序列 $Q_3 = 5$,因为 $\{3\}, \{3, 4\}, \{2\}, \{2, 4\}$ 和 $\{4\}$ 是 $\{3, 2, 4\}$ 的唯一递增子序列 $Q_4 = 6$,因为 $\{3\}, \{3, 4\}, \{2\}, \{2, 4\}, \{4\}$ 和 $\{1\}$ 是 $\{3, 2, 4, 1\}$ 的唯一递增子序列。

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

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.