B - Ranking with Ties Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 200200

問題文

11 から NN までの番号が付けられた NN 人の人がとあるコンテストに参加し、人 i (1iN)i\ (1\leq i\leq N)得点PiP_i でした。

このコンテストでは、以下の手順によって NN 人それぞれの 順位 が定まります。

  1. 変数 rr を用意し、r=1r=1 と初期化する。最初、NN 人の順位はすべて未確定である。
  2. NN 人全員の順位が確定するまで以下の操作を繰り返す。
    • 順位が未確定である人の中での得点の最大値を xx とし、得点が xx である人の数を kk とおく。得点が xx である kk 人すべての順位を rr 位と確定させたのち、rrkk を足す。

NN 人それぞれの順位を出力してください。

制約

  • 1N1001\leq N \leq 100
  • 1Pi1001\leq P_i\leq 100
  • 入力は全て整数

入力

入力は以下の形式で標準入力から与えられる。

NN
P1P_1 P2P_2 \dots PNP_N

出力

NN 行出力せよ。 i (1iN)i\ (1\leq i \leq N) 行目には、人 ii の順位を整数として出力せよ。


入力例 1Copy

Copy
4
3 12 9 9

出力例 1Copy

Copy
4
1
2
2

以下のようにして N (=4)N\ (=4) 人それぞれの順位が定まります。

  1. 変数 rr を用意し、r=1r=1 と初期化する。最初、44 人の順位はすべて未確定である。
  2. 現時点で順位が未確定なのは人 1,2,3,41,2,3,4 であり、その中での得点の最大値は P2 (=12)P_2\ (=12) である。よって、人 22 の順位を r (=1)r\ (=1) 位と確定させたのち、rr11 を足して r=2r=2 とする。
  3. 現時点で順位が未確定なのは人 1,3,41,3,4 であり、その中での得点の最大値は P3=P4 (=9)P_3=P_4\ (=9) である。よって、人 3,43,4 の順位を r (=2)r\ (=2) 位と確定させたのち、rr22 を足して r=4r=4 とする。
  4. 現時点で順位が未確定なのは人 11 であり、その中での得点の最大値は P1 (=3)P_1\ (=3) である。よって、人 11 の順位を r (=4)r\ (=4) 位と確定させたのち、rr11 を足して r=5r=5 とする。
  5. 44 人全員の順位が確定したため、手順を終了する。

入力例 2Copy

Copy
3
3 9 6

出力例 2Copy

Copy
3
1
2

入力例 3Copy

Copy
4
100 100 100 100

出力例 3Copy

Copy
1
1
1
1

入力例 4Copy

Copy
8
87 87 87 88 41 38 41 38

出力例 4Copy

Copy
2
2
2
1
5
7
5
7

Score : 200200 points

Problem Statement

NN people labeled from 11 to NN participated in a certain contest. The score of person ii (1iN1 \leq i \leq N) was PiP_i.

In this contest, the rank of each of the NN people is determined by the following procedure:

  1. Prepare a variable rr, and initialize r=1r = 1. Initially, the ranks of the NN people are all undetermined.
  2. Repeat the following operation until the ranks of all NN people are determined:
    • Let xx be the maximum score among the people whose ranks are currently undetermined, and let kk be the number of people whose score is xx. Determine the rank of those kk people with score xx to be rr, and then add kk to rr.

Print the rank of each of the NN people.

Constraints

  • 1N1001\leq N \leq 100
  • 1Pi1001\leq P_i \leq 100
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN
P1P_1 P2P_2 \dots PNP_N

Output

Print NN lines. The ii-th line (1iN1 \leq i \leq N) should contain the rank of person ii as an integer.


Sample Input 1Copy

Copy
4
3 12 9 9

Sample Output 1Copy

Copy
4
1
2
2

The ranks of the N (=4)N\ (=4) people are determined as follows:

  1. Prepare a variable rr and initialize r=1r=1. At first, the ranks of all 44 people are undetermined.
  2. Currently, persons 1,2,3,41, 2, 3, 4 have undetermined ranks. The maximum score among them is P2 (=12)P_2\ (=12). Therefore, determine the rank of person 22 to be r (=1)r\ (=1), and then add 11 to rr, making r=2r=2.
  3. Currently, persons 1,3,41, 3, 4 have undetermined ranks. The maximum score among them is P3=P4 (=9)P_3=P_4\ (=9). Therefore, determine the ranks of persons 33 and 44 to be r (=2)r\ (=2), and then add 22 to rr, making r=4r=4.
  4. Currently, person 11 has an undetermined rank. The maximum score among them is P1 (=3)P_1\ (=3). Therefore, determine the rank of person 11 to be r (=4)r\ (=4), and then add 11 to rr, making r=5r=5.
  5. The ranks of all 44 people are now determined, so the process ends.

Sample Input 2Copy

Copy
3
3 9 6

Sample Output 2Copy

Copy
3
1
2

Sample Input 3Copy

Copy
4
100 100 100 100

Sample Output 3Copy

Copy
1
1
1
1

Sample Input 4Copy

Copy
8
87 87 87 88 41 38 41 38

Sample Output 4Copy

Copy
2
2
2
1
5
7
5
7


2025-04-14 (Mon)
12:53:39 +00:00