QOJ.ac

QOJ

Limite de temps : 6 s Limite de mémoire : 10 MB Points totaux : 100

#5282. 多关键字排序

Statistiques

考虑一个包含行和列的表格。列的编号从 $1$ 到 $C$。为简单起见,表格中的项均为由小写字母组成的字符串。

Col. 1 Col. 2 Col. 3 Col. 1 Col. 2 Col. 3 Col. 1 Col. 2 Col. 3
apple red sweet banana brown rotten apple green sour
apple green sour apple green sour apple red sweet
pear green sweet pear green sweet banana brown rotten
banana yellow sweet apple red sweet banana yellow sweet
banana brown rotten banana yellow sweet pear green sweet
表格 1 表格 2 表格 3

我们定义作用于此类表格的操作 $\text{Sort}(k)$:$\text{Sort}(k)$ 按照第 $k$ 列的值对表格的行进行排序(同时列的顺序保持不变)。该排序是稳定的,即在第 $k$ 列中具有相同值的行,将保持它们在排序前的相对顺序。例如,对表格 1 应用 $\text{Sort}(2)$ 得到表格 2。

我们关注此类排序操作的序列。这些操作依次作用于同一个表格。例如,对表格 1 依次应用序列 $\text{Sort}(2); \text{Sort}(1)$ 得到表格 3。

如果两个排序操作序列对于任何表格产生相同的效果,则称它们是等价的。例如,$\text{Sort}(2); \text{Sort}(2); \text{Sort}(1)$ 与 $\text{Sort}(2); \text{Sort}(1)$ 等价。然而,它与 $\text{Sort}(1); \text{Sort}(2)$ 不等价,因为它们对表格 1 的作用效果不同。

给定一个排序操作序列,确定一个最短的等价序列。

输入格式

第一行包含两个整数 $C$ 和 $N$。$C$ ($1 \le C \le 1\,000\,000$) 是列数,$N$ ($1 \le N \le 3\,000\,000$) 是排序操作的次数。第二行包含 $N$ 个整数 $k_i$ ($1 \le k_i \le C$),定义了排序操作序列 $\text{Sort}(k_1); \dots; \text{Sort}(k_N)$。

输出格式

第一行包含一个整数 $M$,表示与输入序列等价的最短排序操作序列的长度(子任务 A)。第二行包含 $M$ 个整数,表示该最短序列(子任务 B)。如果仅解决子任务 A,可以省略第二行。

样例

输入格式 1

4 6
1 2 1 2 3 3

输出格式 1

3
1 2 3

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.