#C3102. Lexicographically Smallest Mapping
Lexicographically Smallest Mapping
Lexicographically Smallest Mapping
In this problem, you are given (t) test cases. For each test case, you are provided an integer (n) and a sequence (b = [b_1, b_2, \dots, b_n]) of positive integers. Your task is to construct a new sequence (c) of length (n) based on the following rule: for the first occurrence of each unique number in (b), assign the smallest positive integer that has not been assigned yet; for subsequent occurrences of the same number, reuse the number already assigned. This process ensures that the resulting sequence (c) is the lexicographically smallest possible sequence under this mapping.
For example, consider (b = [4, 2, 2, 7, 4]). The first unique element 4 is mapped to 1. Next, 2 (which is new) is mapped to 2. The next occurrence of 2 uses 2 again. Then 7 is mapped to 3, and the final occurrence of 4 uses 1. Thus, the output (c) is [1, 2, 2, 3, 1].
inputFormat
The input is given from standard input as follows:
The first line contains an integer (t) (the number of test cases). Each test case consists of two lines. The first line of a test case contains an integer (n), representing the length of the sequence (b). The second line contains (n) space-separated integers, representing the sequence (b).
outputFormat
For each test case, output a single line on standard output containing (n) space-separated integers, which is the sequence (c) computed based on the rules described above.## sample
3
5
4 2 2 7 4
3
1 3 3
7
10 20 30 10 20 30 10
1 2 2 3 1
1 2 2
1 2 3 1 2 3 1
</p>