#P9587. 「MXOI Round 2」排名

    ID: 10789 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>动态规划 DP贪心洛谷原创O2优化排序前缀和洛谷月赛

「MXOI Round 2」排名

Problem Description

Xiao C has an array aa of length nn.

Xiao C defines f(i)f(i) as the front rank of aia_i, where f(i)f(i) equals the number of elements in array aa that are greater than aia_i, plus 11.

Xiao C also defines g(i)g(i) as the back rank of aia_i, where g(i)g(i) equals the number of elements in array aa that are greater than or equal to aia_i.

In each operation, Xiao C needs to choose a positive integer tt not greater than nn, and increase the value of ata_t by 11.

Xiao C wants to know, for each 1in1 \le i \le n, in order to make f(i)kg(i)f(i) \le k \le g(i) hold, what is the minimum number of operations needed?

It can be proven that there is always at least one sequence of operations that makes f(i)kg(i)f(i) \le k \le g(i).

Input Format

The first line contains three integers c,n,kc,n,k, where cc indicates the test point ID. c=0c=0 means this test point is the sample.

The second line contains nn integers, representing the given array aa.

Output Format

Output nn lines in total, each containing one integer. The integer on line ii indicates the minimum number of operations needed to make f(i)kg(i)f(i) \le k \le g(i) hold.

0 6 3
1 1 4 5 1 4
3
3
0
2
3
0

Hint

Sample Explanation #1

When i=1i=1, Xiao C can choose t=1t=1 and perform 33 operations. Then f(i)=2f(i)=2 and g(i)=4g(i)=4, satisfying f(i)kg(i)f(i) \le k \le g(i). It can be proven that Xiao C needs at least 33 operations in this case.

When i=4i=4, Xiao C can first choose t=3t=3 and perform 11 operation, then choose t=6t=6 and perform 11 operation. Then f(i)=1f(i)=1 and g(i)=3g(i)=3, satisfying f(i)kg(i)f(i) \le k \le g(i). It can be proven that Xiao C needs at least 22 operations in this case.

Sample #2

See rank/rank2.in and rank/rank2.ans in the attachment.

This sample satisfies the constraints of test point 77.

Sample #3

See rank/rank3.in and rank/rank3.ans in the attachment.

This sample satisfies the constraints of test point 2020.

Constraints

For 100%100\% of the data, 1kn5×1051 \le k \le n \le 5 \times 10^5, and 1ai1091 \le a_i \le 10^9.

Test Point ID nn \le aia_i \le Special Property
161\sim6 20002000 10910^9 A
7107\sim10 None
111411\sim14 5×1055\times10^5 B
152015\sim20 None

Special Property A: It is guaranteed that for all 1i<n1 \le i \lt n, aiai+1a_i \ge a_{i+1} holds.

Special Property B: It is guaranteed that k=1k=1.

Translated by ChatGPT 5