Official

C - Bib Editorial by en_translator


Let \(S_i\) be the sought answer.

Person \(i\) is wearing bib \(Q_i\), so the person \(P_i\), whom person \(i\) stares at, is wearing bib \(Q_{P_i}\). Thus, we have \(S_{Q_i}=Q_{P_i}\), so the answer can be found with a for statement like:

for i in 1..n:
  S[Q[i]]= Q[P[i]]

Note that most programming languages adopts 0-based indices for arrays.

Writer’s solution (Python)

posted:
last update: