(K+1)-th Largest Number

AtCoder
IDabc273_c
Time2000ms
Memory256MB
Difficulty
You are given a sequence $A = (A_1, A_2, \ldots, A_N)$ of length $N$. For each $K = 0, 1, 2, \ldots, N-1$, solve the following problem. > Find the number of integers $i$ between $1$ and $N$ (inclusive) such that: > > * $A$ contains exactly $K$ distinct integers greater than $A_i$. ## Constraints * $1 \leq N \leq 2 \times 10^5$ * $1 \leq A_i \leq 10^9$ * All values in the input are integers. ## Input The input is given from Standard Input in the following format: $N$ $A_1$ $A_2$ $\ldots$ $A_N$ [samples]
Samples
Input #1
6
2 7 1 8 2 8
Output #1
2
1
2
1
0
0

For example, we will find the answer for $K=2$.

*   Regarding $A_1 = 2$, $A$ contains $2$ distinct integers greater than $A_1$: $7$ and $8$.
*   Regarding $A_2 = 7$, $A$ contains $1$ distinct integer greater than $A_2$: $8$.
*   Regarding $A_3 = 1$, $A$ contains $3$ distinct integers greater than $A_3$: $2, 7$, and $8$.
*   Regarding $A_4 = 8$, $A$ contains $0$ distinct integers greater than $A_4$ (there is no such integer).
*   Regarding $A_5 = 2$, $A$ contains $2$ distinct integers greater than $A_5$: $7$ and $8$.
*   Regarding $A_6 = 8$, $A$ contains $0$ distinct integers greater than $A_6$ (there is no such integer).

Thus, there are two $i$'s, $i = 1$ and $i = 5$, such that $A$ contains exactly $K = 2$ distinct integers greater than $A_i$. Therefore, the answer for $K = 2$ is $2$.
Input #2
1
1
Output #2
1
Input #3
10
979861204 57882493 979861204 447672230 644706927 710511029 763027379 710511029 447672230 136397527
Output #3
2
1
2
1
2
1
1
0
0
0
API Response (JSON)
{
  "problem": {
    "name": "(K+1)-th Largest Number",
    "description": {
      "content": "You are given a sequence $A = (A_1, A_2, \\ldots, A_N)$ of length $N$. For each $K = 0, 1, 2, \\ldots, N-1$, solve the following problem. > Find the number of integers $i$ between $1$ and $N$ (inclusiv",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc273_c"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given a sequence $A = (A_1, A_2, \\ldots, A_N)$ of length $N$. For each $K = 0, 1, 2, \\ldots, N-1$, solve the following problem.\n\n> Find the number of integers $i$ between $1$ and $N$ (inclusiv...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments