#B3694. Compute the Rank of Array Elements
Compute the Rank of Array Elements
Compute the Rank of Array Elements
Given a sequence of integers \(a\) of length \(n\). Define the rank \(\mathrm{rank}(i)\) of the element \(a_i\) as the number of distinct elements in \(a\) that are strictly less than \(a_i\) plus one.
In other words, if we sort the distinct values in the array in increasing order, the rank of \(a_i\) is its 1-indexed position in this sorted order. For each \(1 \leq i \leq n\), compute \(\mathrm{rank}(i)\).
inputFormat
The first line contains a single integer \(n\), the length of the sequence. The second line contains \(n\) space-separated integers representing the sequence \(a\).
outputFormat
Output \(n\) space-separated integers where the \(i\)-th integer is \(\mathrm{rank}(i)\).
sample
5
10 40 20 10 30
1 4 2 1 3