atcoder#ABC234D. [ABC234D] Prefix K-th Max

[ABC234D] Prefix K-th Max

Score : 400400 points

Problem Statement

Given are a permutation P=(P1,P2,,PN)P=(P_1,P_2,\ldots,P_N) of (1,2,,N)(1,2,\ldots,N) and a positive integer KK.

For each i=K,K+1,,Ni=K,K+1,\ldots,N, find the following.

  • The KK-th greatest value among the first ii terms of PP.

Constraints

  • 1KN5×1051 \leq K \leq N \leq 5 \times 10^5
  • (P1,P2,,PN)(P_1,P_2,\ldots,P_N) is a permutation of (1,2,,N)(1,2,\ldots,N).
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN KK

P1P_1 P2P_2 \ldots PNP_N

Output

For each i=K,K+1,,Ni=K, K+1, \ldots, N, in this order, print the specified value in Problem Statement, separated by newlines.

3 2
1 2 3
1
2
  • The (K=)(K=) 22-nd greatest value among the first 22 terms of PP, (P1,P2)=(1,2)(P_1,P_2)=(1,2), is 11.
  • The (K=)(K=) 22-nd greatest value among the first 33 terms of PP, (P1,P2,P3)=(1,2,3)(P_1,P_2,P_3)=(1,2,3), is 22.
11 5
3 7 2 5 11 6 1 9 8 10 4
2
3
3
5
6
7
7