#C223. Reconstruct the Permutation
Reconstruct the Permutation
Reconstruct the Permutation
You are given a hidden permutation of the integers \(1,2,\dots,n\) indirectly through an array of responses. For each \(i\) (where \(1 \leq i \leq n\)), a response \(r_i\) is provided such that the original permutation \(p\) satisfies \(p[r_i] = i\). Your task is to reconstruct the permutation \(p\) based on these responses.
Note: All indices and numbers are 1-indexed. It is guaranteed that the list of responses forms a valid permutation of \(\{1, 2, \dots, n\}\).
Example:
Input: 5 2 3 1 5 4</p>For i = 1, response = 2, so p[2] = 1 For i = 2, response = 3, so p[3] = 2 For i = 3, response = 1, so p[1] = 3 For i = 4, response = 5, so p[5] = 4 For i = 5, response = 4, so p[4] = 5
Thus, the permutation p is: 3 1 2 5 4
inputFormat
The first line of input contains a single integer \(n\) representing the length of the permutation. The second line contains \(n\) space-separated integers \(r_1, r_2, \dots, r_n\), which are the responses.
outputFormat
Output the reconstructed permutation \(p\) as \(n\) space-separated integers, where for each \(i\) (\(1 \leq i \leq n\)) the number at the position corresponding to the response is set appropriately.
For the sample above, the output should be:
3 1 2 5 4## sample
5
2 3 1 5 4
3 1 2 5 4