Indices of elements in an array in order from smallest to largest Task

Basically you have an array of random integers e.g.

I() = [1, 4, 3, 2, 5, 3, 2, 1]


and you have to create another array of the same length with the numbers 1 to the size of the array in place of the smallest to largest numbers respectively, e.g.

O() = [1, 7, 5, 3, 8, 6, 4, 2]


For duplicates, the first occurrence is taken as the smaller of the indices.

Test Cases:

Input:   I() = [1, 5, 3, 4, 5, 3, 2, 4]
Output:  O() = [1, 7, 3, 5, 8, 4, 2, 6]

Input:   I() = [1, 5, 3, 2, 5, 3, 2, 4, 6, 6, 5]
Output:  O() = [1, 7, 4, 2, 8, 5, 3, 6, 10, 11, 9]


Rules


It should work with array of any finite length
All integers are positive(greater than 0)
This is code-golf, so the submission with the least amount of bytes wins!
Haskell, 41 bytes



f l|z&lt;-zip l[0..]=[sum[1|q&lt;-z,p&gt;=q]|p&lt;-z]


Try it online!

Haskell doesn't have build-in sorting, so we have to roll up our sleeves. We pair each element with its index with z&lt;-zip l[0..], then for each pair counts the number of pairs that are smaller or equal. This first compares the values, then tiebreaks by their index.