Prefix K-th Max

AtCoder
IDabc234_d
Time2000ms
Memory256MB
Difficulty
Given are a permutation $P=(P_1,P_2,\ldots,P_N)$ of $(1,2,\ldots,N)$ and a positive integer $K$. For each $i=K,K+1,\ldots,N$, find the following. * The $K$\-th greatest value among the first $i$ terms of $P$. ## Constraints * $1 \leq K \leq N \leq 5 \times 10^5$ * $(P_1,P_2,\ldots,P_N)$ is a permutation of $(1,2,\ldots,N)$. * All values in input are integers. ## Input Input is given from Standard Input in the following format: $N$ $K$ $P_1$ $P_2$ $\ldots$ $P_N$ [samples]
Samples
Input #1
3 2
1 2 3
Output #1
1
2

*   The $(K=)$ $2$\-nd greatest value among the first $2$ terms of $P$, $(P_1,P_2)=(1,2)$, is $1$.
*   The $(K=)$ $2$\-nd greatest value among the first $3$ terms of $P$, $(P_1,P_2,P_3)=(1,2,3)$, is $2$.
Input #2
11 5
3 7 2 5 11 6 1 9 8 10 4
Output #2
2
3
3
5
6
7
7
API Response (JSON)
{
  "problem": {
    "name": "Prefix K-th Max",
    "description": {
      "content": "Given are a permutation $P=(P_1,P_2,\\ldots,P_N)$ of $(1,2,\\ldots,N)$ and a positive integer $K$. For each $i=K,K+1,\\ldots,N$, find the following. *   The $K$\\-th greatest value among the first $i$ te",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc234_d"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Given are a permutation $P=(P_1,P_2,\\ldots,P_N)$ of $(1,2,\\ldots,N)$ and a positive integer $K$.\nFor each $i=K,K+1,\\ldots,N$, find the following.\n\n*   The $K$\\-th greatest value among the first $i$ te...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments