Fight for the throne

A country is currently kingless. To choose a new king, n warriors,
numbered 1…n, will fight as follows: First, 1 arrives and sits on the
throne. Afterwards, 2…n arrive in order to challenge the current
champion. Every time, the winner of the fight sits on the throne, and
the loser escapes. At the end, the champion on the throne is declared
the king.

Now, let us assume that each warrior has a different strength between 1
and n, and that the outcome of each fight is only determined by the
relative strengths of both fighters. Let w_(i) be the number of the
warrior on the throne at time i. Knowing the numbers w_(i), can you
bound the minimum and the maximum possible strength of each warrior?

Input

Input consists of several cases, each one with n followed by
w₁, …, w_(n). You can assume 1 ≤ n ≤ 10⁵, w₁ = 1, and that, for each
2 ≤ i ≤ n, w_(i) is either i or w_(i − 1).

Output

For every case, print n + 1 lines: For every warrior i, print the
interval of his possible strength, or just his strength if you can
decide it for sure. Finally, print a line with 10 dashes.

Problem information

Author: Salvador Roura

Generation: 2026-01-25T11:46:32.168Z

© Jutge.org, 2006–2026.
https://jutge.org
