C - Inverse of Permutation Editorial by ksun48


From the problem statement, we know that the \(p_i\)-th element of Q is \(i\). The easiest way to do this is make an array Q of \(n\) elements, initially all blank, and set the \(p_i\)th element to \(i\). Since \(p\) is a permutation, all of \(1\) through \(n\) appear as some \(p_i\) so our array Q will be full once we’ve added in every constraint.

Here is an example solution: https://atcoder.jp/contests/abc217/submissions/25561191.

posted:
last update: