#abc260d. D - Draw Your Cards

D - Draw Your Cards

Score : 400400 points

问题描述

有一副包含 NN 张面朝下的扑克牌,每张牌上都写有一个从 11NN 的整数。第 ii 张从顶部开始的牌上的整数为 PiP_i

使用这副牌,你需要执行 NN 次操作,每次操作包括以下步骤:

  • 从牌堆顶部抽一张牌。设此牌上所写的整数为 XX
  • 将抽出的牌(面朝上)放在桌面上所有面朝上的最顶部牌中,整数值大于等于 XX 的最小整数值的牌之上。如果桌面上没有这样的牌,则将抽出的牌面朝上放在桌面上,不叠加在任何牌上。
  • 接着,如果桌面上有由 KK 张面朝上的牌组成的一堆牌,吃掉所有这些牌。被吃掉的牌都会从桌面上消失。

对于每张牌,请找出它在哪一次操作中被吃掉。如果该牌直到最后都没有被吃掉,则报告这一事实。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There is a deck consisting of NN face-down cards with an integer from 11 through NN written on them. The integer on the ii-th card from the top is PiP_i.

Using this deck, you will perform NN moves, each consisting of the following steps:

  • Draw the topmost card from the deck. Let XX be the integer written on it.
  • Stack the drawn card, face up, onto the card with the smallest integer among the face-up topmost cards on the table with an integer greater than or equal to XX written on them. If there is no such card on the table, put the drawn card on the table, face up, without stacking it onto any card.
  • Then, if there is a pile consisting of KK face-up cards on the table, eat all those cards. The eaten cards all disappear from the table.

For each card, find which of the NN moves eats it. If the card is not eaten until the end, report that fact.

Constraints

  • All values in input are integers.
  • 1KN2×1051 \le K \le N \le 2 \times 10^5
  • PP is a permutation of (1,2,,N)(1,2,\dots,N) (i.e. a sequence obtained by rearranging (1,2,,N)(1,2,\dots,N)).

Input

Input is given from Standard Input in the following format:

NN KK

P1P_1 P2P_2 \dots PNP_N

Output

Print NN lines.
The ii-th line (1iN1 \le i \le N) should describe the card with the integer ii written on it. Specifically,

  • if the card with ii written on it is eaten in the xx-th move, print xx;
  • if that card is not eaten in any move, print 1-1.

Sample Input 1

5 2
3 5 2 1 4

Sample Output 1

4
3
3
-1
4

In this input, P=(3,5,2,1,4)P=(3,5,2,1,4) and K=2K=2.

  • In the 11-st move, the card with 33 written on it is put on the table, face up, without stacked onto any card.
  • In the 22-nd move, the card with 55 written on it is put on the table, face up, without stacked onto any card.
  • In the 33-rd move, the card with 22 written on it is stacked, face up, onto the card with 33 written on it.
    • Now there is a pile consisting of K=2K=2 face-up cards, on which 22 and 33 from the top are written, so these cards are eaten.
  • In the 44-th move, the card with 11 written on it is stacked, face up, onto the card with 55 written on it.
    • Now there is a pile consisting of K=2K=2 face-up cards, on which 11 and 55 from the top are written, so these cards are eaten.
  • In the 55-th move, the card with 44 written on it is put on the table, face up, without stacked onto any card.
  • The card with 44 written on it was not eaten until the end.

Sample Input 2

5 1
1 2 3 4 5

Sample Output 2

1
2
3
4
5

If K=1K=1, every card is eaten immediately after put on the table within a single move.

Sample Input 3

15 3
3 14 15 9 2 6 5 13 1 7 10 11 8 12 4

Sample Output 3

9
9
9
15
15
6
-1
-1
6
-1
-1
-1
-1
6
15

update @ 2024/3/10 11:01:39

}