QOJ.ac

QOJ

时间限制: 2.0 s 内存限制: 256 MB 总分: 100

#12752. 碎片化

统计

Felix 正在车库里进行一个创业项目。他已经为他的项目起了一个响亮的名字:SuperFastZilla。目前他还不确定 SuperFastZilla 应该做什么,但他非常确定它必须运行得很快,超级快。

有一次,他注意到尽管使用了快速算法,SuperFastZilla 的运行速度依然很慢。Felix 认为这个问题可能是由存储碎片化引起的。

SuperFastZilla 使用的存储空间由 $n$ 个内存块组成。SuperFastZilla 在此存储空间上执行一些操作。每个内存块仅用于一次操作,第 $i$ 个内存块用于第 $a_i$ 次操作。

Felix 想要按照操作的索引对这些内存块进行排序。为了提高速度,Felix 想要将存储空间分割成最少数量的连续内存块片段,然后重新排列这些片段,以得到排序后的内存块数组。重新排列后,内存块的操作索引顺序必须是非递减的。

请帮助 Felix 找到一种分割存储空间的方法,使得片段数量最少。

例如,如果 $a = [2, 3, 1, 1, 2, 2, 1]$,它可以被分割成三个部分:$[2, 3]$,$[1, 1, 2, 2]$ 和 $[1]$。这些部分可以重新排列以组成排序后的数组:$[1]$,$[1, 1, 2, 2]$,$[2, 3]$。

输入格式

输入文件的第一行包含一个整数 $n$ ($1 \le n \le 10^5$)。下一行包含 $n$ 个整数 $a_i$ ($1 \le a_i \le 10^5$)。

输出格式

输出文件的第一行必须包含一个整数 $m$ —— 最少的片段数量。 下一行必须包含 $m$ 个整数,即从左到右各片段的长度。

样例

输入 1

7
2 3 1 1 2 2 1

输出 1

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