QOJ.ac

QOJ

実行時間制限: 2.0 s メモリ制限: 512 MB 満点: 100

#17599. K-TI

統計

給定一個數列與一個自然數 $K$。

我們在數列中尋找位置為 $K$ 的倍數之數字中的最大值,其中數列的位置從 $0$ 開始計算。換句話說,我們在位置 $0, K, 2K, 3K, \dots$ 處尋找最大值。若此類最大值有多個,則選擇第一個出現的最大值。將找到的數字從數列中刪除,隨後該數字之後的所有數字會自動向左移動一個位置,填補產生的「空缺」。

重複上述步驟直到數列中沒有數字為止。請寫一個程式來執行此操作。

輸入格式

第一行包含自然數 $N$ 與 $K$ ($2 \le K \le N \le 100\,000$)。

下一行包含 $N$ 個自然數,其值皆在區間 $[1, N]$ 內,依序代表從第 $0$ 個到第 $(N - 1)$ 個數字的數列。

輸出格式

輸出 $N$ 個自然數,其中第 $i$ 個輸出的數字為第 $i$ 次操作中刪除的數字。

子任務

子任務 分數 額外限制
1 7 $N \le 1000$
2 25 $K = 2$
3 23 $K \le 10$
4 25 $100 \le K \le N$
5 20 無額外限制

範例

輸入 1

10 2
2 3 1 9 10 4 5 6 1 5

輸出 1

10
6
4
5
2
9
3
5
1
1

輸入 2

10 3
2 3 1 9 10 4 5 6 1 5

輸出 2

9
10
4
5
6
2
5
3
1
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.