QOJ.ac

QOJ

حد الوقت: 2.0 s حد الذاكرة: 1024 MB مجموع النقاط: 100 قابلة للهجوم ✓

#18460. 直方图序列 3

الإحصائيات

考虑一个由 $n$ 个边长分别为 $a_1, a_2, \dots, a_n$ 的正方形组成的直方图。我们称序列 $(a_1, a_2, \dots, a_n)$ 为该直方图的直方图序列。

考虑该直方图中每一列的高度。前 $a_1$ 列的高度均为 $a_1$,接下来的 $a_2$ 列的高度均为 $a_2$,……,最后的 $a_n$ 列的高度均为 $a_n$。

现在,我们定义高度序列为 $(b_1, b_2, \dots, b_{a_1+a_2+\dots+a_n})$,其中 $b_j$ ($1 \le j \le a_1 + a_2 + \dots + a_n$) 表示第 $j$ 列的高度。

例如,直方图序列为 $(3, 2, 1, 4)$ 的直方图,其对应的高度序列为 $(3, 3, 3, 2, 2, 1, 4, 4, 4, 4)$。

编写一个程序,在给定高度序列的情况下,求出其对应的直方图序列。

输入格式

第一行包含一个整数 $m$ ($1 \le m \le 10^6$),表示给定的高度序列 $\{b_i\}$ 的长度。

第二行包含 $m$ 个整数,表示高度序列。具体来说,该行中的第 $i$ 个整数为 $b_i$ ($1 \le b_i \le m$)。

输入数据保证给定的高度序列一定对应一个合法的直方图序列。

输出格式

在一行中输出 $n$ 个整数 $a_1, a_2, \dots, a_n$,其中 $(a_1, a_2, \dots, a_n)$ 是与给定高度序列对应的直方图序列。如果存在多个可能的答案,输出其中任意一个即可。

样例

输入样例 1

10
3 3 3 2 2 1 4 4 4 4

输出样例 1

3 2 1 4

输入样例 2

5
2 2 2 2 1

输出样例 2

2 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.