QOJ.ac

QOJ

Time Limit: 3.0 s Memory Limit: 256 MB Total points: 100

#17674. NM 個字元

Statistics

Busy Beaver 正在為他的語言學課程創造一種新語言!他已經決定他的語言將擁有一個字母表,其中的字母依序為整數 $1, \dots, NM$;現在他想要為這種語言造一些單字。

由於 Busy Beaver 對統計學感興趣,他想要控制單字中出現的字母頻率,因此他從字母表中選擇了一個大小為 $NM$ 的字母多重集 $a$。他現在要組成 $N$ 個單字,每個單字包含 $M$ 個字母,使得多重集 $a$ 中的每個字母恰好被使用一次(即,如果給定的字母 $x$ 在 $a$ 中出現恰好 $k$ 次,則它在所有 $N$ 個單字中總共被使用恰好 $k$ 次)。

在組成這些單字後,Busy Beaver 計畫將它們整理成一本字典,因此他會將這 $N$ 個單字按字典順序排序,產生單字序列 $s_1, \dots, s_N$。Busy Beaver 喜歡字典順序較小的字串,因此對於每個從 $1$ 到 $N$ 的 $k$,他想要知道在所有可能的單字選擇下,$s_k$ 的字典順序最小值。

注意,每個 $s_k$ 的答案是獨立的;例如,為了使 $s_1$ 最小化而選擇的單字,可能與為了使 $s_2$ 最小化而選擇的單字不同。

輸入格式

第一行包含兩個正整數 $N, M$ ($1 \le NM \le 10^6$)。

第二行包含 $NM$ 個整數 $a_1, \dots, a_{NM}$,組成多重集 $a$ ($1 \le a_j \le NM$)。

輸出格式

對於每個從 $1$ 到 $N$ 的 $k$,輸出 $s_k$ 的最小可能值,每個值佔一行,以空格分隔的整數序列表示。

範例

輸入 1

4 3
1 1 2 2 3 3 4 4 5 5 6 6

輸出 1

1 1 2
1 2 3
2 2 3
2 3 4

輸入 2

3 4
12 4 4 4 1 1 4 4 6 4 1 4

輸出 2

1 1 1 4
1 4 4 4
1 4 4 12

輸入 3

4 5
12 7 17 3 6 11 9 2 17 7 1 6 9 12 6 3 9 12 2 15

輸出 3

1 2 2 3 3
2 2 3 3 6
2 3 6 7 7
3 3 6 6 6

輸入 4

1 1
1

輸出 4

1

說明

在第一個範例中,以下單字選擇使每個 $s_k$ 最小化:

透過選擇單字 112, 233, 445, 566,我們得到 $s = 112, 233, 445, 566$,因此 $s_1 = 112$ 如預期。

透過選擇單字 123, 456, 123, 456,我們得到 $s = 123, 123, 456, 456$,因此 $s_2 = 123$ 如預期。

透過選擇單字 166, 155, 344, 223,我們得到 $s = 155, 166, 223, 344$,因此 $s_3 = 223$ 如預期。

透過選擇單字 234, 234, 156, 156,我們得到 $s = 156, 156, 234, 234$,因此 $s_4 = 234$ 如預期。

可以證明在所有這些情況下,沒有辦法選擇單字使得對應的 $s_k$ 在字典順序上更小。

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.