Problems > Rank Transform

Rank Transform

Difficulty: 1300 3000 ms 128 MB

sorting

Replace each value by its rank: the smallest distinct value becomes 1, the next 2, and so on (equal values share a rank).

Input: the first line has N; the second line has N integers.

Output: the N ranks in the original order.

Constraints:

  • 1 ≤ N ≤ 105
  • −109 ≤ ai ≤ 109

Sample Tests

Input 1
5
40 10 20 20 30
Output 1
4 1 2 2 3
Input 2
1
-5
Output 2
1

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.