#abc273c. C - (K+1)-th Largest Number

C - (K+1)-th Largest Number

Score : 300300 points

问题描述

给定一个长度为 NN 的序列 A=(A1,A2,,AN)A = (A_1, A_2, \ldots, A_N)。对于每个 K=0,1,2,,N1K = 0, 1, 2, \ldots, N-1,解决以下问题。

找出满足以下条件的整数 ii 的个数,其中 ii 的取值范围在 11NN(包含)之间:

  • 在序列 AA 中,恰好有 KK 个不重复的整数大于 AiA_i

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

Problem Statement

You are given a sequence A=(A1,A2,,AN)A = (A_1, A_2, \ldots, A_N) of length NN. For each K=0,1,2,,N1K = 0, 1, 2, \ldots, N-1, solve the following problem.

Find the number of integers ii between 11 and NN (inclusive) such that:

  • AA contains exactly KK distinct integers greater than AiA_i.

Constraints

  • 1N2×1051 \leq N \leq 2 \times 10^5
  • 1Ai1091 \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:

NN

A1A_1 A2A_2 \ldots ANA_N

Output

Print NN lines. For i=1,2,,Ni = 1, 2, \ldots, N, the ii-th line should contain the answer for K=i1K = i-1.

Sample Input 1

6
2 7 1 8 2 8

Sample Output 1

2
1
2
1
0
0

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

  • Regarding A1=2A_1 = 2, AA contains 22 distinct integers greater than A1A_1: 77 and 88.
  • Regarding A2=7A_2 = 7, AA contains 11 distinct integer greater than A2A_2: 88.
  • Regarding A3=1A_3 = 1, AA contains 33 distinct integers greater than A3A_3: 2,72, 7, and 88.
  • Regarding A4=8A_4 = 8, AA contains 00 distinct integers greater than A4A_4 (there is no such integer).
  • Regarding A5=2A_5 = 2, AA contains 22 distinct integers greater than A5A_5: 77 and 88.
  • Regarding A6=8A_6 = 8, AA contains 00 distinct integers greater than A6A_6 (there is no such integer).

Thus, there are two ii's, i=1i = 1 and i=5i = 5, such that AA contains exactly K=2K = 2 distinct integers greater than AiA_i. Therefore, the answer for K=2K = 2 is 22.

Sample Input 2

1
1

Sample Output 2

1

Sample Input 3

10
979861204 57882493 979861204 447672230 644706927 710511029 763027379 710511029 447672230 136397527

Sample Output 3

2
1
2
1
2
1
1
0
0
0

update @ 2024/3/10 11:29:56