#C2348. Positions in Descending Sorted Order

    ID: 45654 Type: Default 1000ms 256MiB

Positions in Descending Sorted Order

Positions in Descending Sorted Order

Given a list of integers, your task is to determine, for each integer, its rank (position) if the list were sorted in descending order (largest element has rank 1). In the event of duplicate numbers, assign the same rank based on the first occurrence in the sorted order.

Formally, let (A = [a_1, a_2, \dots, a_n]) be the input array. Let (B) be the array obtained by sorting (A) in descending order. For each (a_i) in (A), output (\text{rank}(a_i) = \min{j : B_j = a_i} ), where the indices are 1-indexed.

Example: If (A = [4, 2, 10, 7, 6]), the sorted array is (B = [10, 7, 6, 4, 2]). The ranks are computed as follows:

  • 4 appears at position 4 in (B), so its rank is 4.
  • 2 appears at position 5, so its rank is 5.
  • 10 appears at position 1, so its rank is 1.
  • 7 appears at position 2, so its rank is 2.
  • 6 appears at position 3, so its rank is 3. Thus, the output is [4, 5, 1, 2, 3].

inputFormat

The first line of input contains an integer (n) (the number of numbers). The second line contains (n) space-separated integers.

outputFormat

Output (n) integers in a single line separated by spaces, where the (i)-th integer represents the position (rank) of the corresponding number in the descending sorted order.## sample

5
4 2 10 7 6
4 5 1 2 3