Redaksiya
Let be a given permutation. Its application means moving an element from position to position , i.e., the transformation occurs. The inverse permutation of , denoted as , will have the inverse transformation where takes place. In other words, in the array , the number should be placed at position .
Example
Consider the permutation and its inverse . In the inverse permutation the edges are oriented in the opposite direction.
Algorithm realization
The array stores the input permutation, and the array stores the inverse permutation.
#define MAX 20010 int p[MAX], pi[MAX];
Read the input permutation.
scanf("%d",&n); for(i = 1; i <= n; i++) scanf("%d",&p[i]);
Compute the inverse permutation.
for(i = 1; i <= n; i++) pi[p[i]] = i;
Print the inverse permutation.
for(i = 1; i <= n; i++) printf("%d ",pi[i]); printf("\n");
Python realization
The list stores the input permutation, and the list stores the inverse permutation. Read the input data.
n = int(input()) p = [0] + list(map(int, input().split())) pi = [0] * (n + 1)
Compute the inverse permutation.
for i in range(1, n + 1): pi[p[i]] = i
Print the inverse permutation.
for i in range(1, n + 1): print(pi[i], end=" ") print()