#K54257. Exclusive Sort Algorithm
Exclusive Sort Algorithm
Exclusive Sort Algorithm
Given an array of integers, perform an Exclusive Sort transformation on the array. In this transformation, each element is replaced by its rank (1-indexed) when considering the sorted list of all distinct elements from the array.
Formally, let \(S = \{a_1, a_2, \ldots, a_n\}\) be the input array and let \(U\) be the set of unique elements in \(S\). If \(U_{sorted}\) is the sorted list of the unique elements, then each element \(x\) in the original array is replaced by its rank defined as:
[ \text{rank}(x) = \min { i : U_{sorted}[i] = x } + 1 ]
For example, if the array is [10, 20, 10, 30, 20], the sorted unique list is [10, 20, 30] and the transformed array becomes [1, 2, 1, 3, 2].
inputFormat
The input is read from standard input (stdin) and has the following format:
n a1 a2 a3 ... an
where n
is the number of elements in the array, followed by n
space-separated integers representing the array elements.
outputFormat
Output the transformed array to standard output (stdout) as space-separated integers in a single line.
## sample5
10 20 10 30 20
1 2 1 3 2
</p>