#abc234d. D - Prefix K-th Max

D - Prefix K-th Max

Score : 400400 points

问题描述

已知一个由 (1,2,,N)(1,2,\ldots,N) 的排列 P=(P1,P2,,PN)P=(P_1,P_2,\ldots,P_N) 和一个正整数 KK

对于每个 i=K,K+1,,Ni=K,K+1,\ldots,N,找出以下内容:

  • PP 的前 ii 项中第 KK 大的值。

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

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.

Sample Input 1

3 2
1 2 3

Sample Output 1

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.

Sample Input 2

11 5
3 7 2 5 11 6 1 9 8 10 4

Sample Output 2

2
3
3
5
6
7
7

update @ 2024/3/10 10:10:04