LIS and Inversion

AtCoder
IDarc180_e
Time2000ms
Memory256MB
Difficulty
You are given an integer sequence $A=(A_1,A_2,\cdots,A_N)$ of length $N$. Here, it is guaranteed that $0 \leq A_i < i$ for each $i$. The **score** and **cost** of a permutation $P=(P_1,P_2,\cdots,P_N)$ of $(1,2,\cdots,N)$ are defined as follows: * The score of $P$ is the length of a longest increasing subsequence of $P$. * The cost of $P$ is the number of integers $i$ ($1 \leq i \leq N$) that satisfy the following condition: * There are fewer than $A_i$ integers $j$ such that $j < i$ and $P_j > P_i$. For each $k=1,2,\cdots,N$, solve the following problem: * Find the minimum cost of a permutation $P$ whose score is at least $k$. ## Constraints * $1 \leq N \leq 250000$ * $0 \leq A_i < i$ * All input values are integers. ## Input The input is given from Standard Input in the following format: $N$ $A_1$ $A_2$ $\cdots$ $A_N$ [samples]
Samples
Input #1
4
0 1 2 1
Output #1
0 0 1 3

For each $k$, a solution $P$ is as follows:

*   $k=1$: If $P=(4,2,1,3)$, then $P$ has the score of $2$ and the cost of $0$.
*   $k=2$: If $P=(4,3,1,2)$, then $P$ has the score of $2$ and the cost of $0$.
*   $k=3$: If $P=(4,1,2,3)$, then $P$ has the score of $3$ and the cost of $1$.
*   $k=4$: If $P=(1,2,3,4)$, then $P$ has the score of $4$ and the cost of $3$.
Input #2
3
0 0 0
Output #2
0 0 0
Input #3
5
0 1 2 3 4
Output #3
0 1 2 3 4
Input #4
11
0 0 2 3 4 5 3 7 8 2 10
Output #4
0 0 0 1 2 3 4 5 7 8 9
API Response (JSON)
{
  "problem": {
    "name": "LIS and Inversion",
    "description": {
      "content": "You are given an integer sequence $A=(A_1,A_2,\\cdots,A_N)$ of length $N$. Here, it is guaranteed that $0 \\leq A_i < i$ for each $i$. The **score** and **cost** of a permutation $P=(P_1,P_2,\\cdots,P_N)",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "arc180_e"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given an integer sequence $A=(A_1,A_2,\\cdots,A_N)$ of length $N$. Here, it is guaranteed that $0 \\leq A_i < i$ for each $i$.\nThe **score** and **cost** of a permutation $P=(P_1,P_2,\\cdots,P_N)...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments