| BioCode 2024 |
|---|
| Finished |
Sanchali is a researcher who wants to protect an endangered species of trees. Their habitat consists of $$$n$$$ forests arranged in a line, where the $$$i$$$-th forest has a density of $$$t_i$$$.
Unfortunately, this habitat is very vulnerable to wildfires. A forest is either healthy or is burning with a wildfire of some integer strength $$$k \gt 0$$$. Wildfires can spread to adjacent forests (forests $$$i$$$ and $$$j$$$ are adjacent if $$$\lvert i - j \rvert = 1$$$).
For a pair of adjacent forests $$$i$$$ and $$$j$$$, if forest $$$i$$$ is healthy but forest $$$j$$$ has a wildfire of strength $$$k$$$, then a wildfire of strength $$$k'$$$ starts in forest $$$i$$$, where
$$$k' = \begin{cases} k+1 & k \lt t_i \\ k & k = t_i \\ k-1 & k \gt t_i \\ \end{cases} $$$
If $$$k' = 0$$$, no fire starts.
For each $$$i$$$ from $$$1$$$ to $$$n$$$, find the minimum strength needed for a wildfire to start at forest $$$i$$$ and burn all of the $$$n$$$ forests in the habitat.
The first line of the input will contain an integer $$$n$$$ ($$$1 \leq n \leq 5 \cdot 10^5$$$) representing the number of forests.
The second line will contain $$$n$$$ integers $$$t_1 \dots t_n$$$ ($$$0 \leq t_i \leq n$$$) representing the density of trees in each forest.
Print $$$n$$$ integers representing the minimum strength needed for a wildfire to start at each forest and burn all the forests in the habitat.
70 0 3 1 2 0 5
2 2 3 2 3 4 5
In the sample, a wildfire starting at forest $$$1$$$ can burn all of the $$$n$$$ forests with strength $$$2$$$.
Thus, the wildfire will reach all $$$n$$$ forests. On the other hand, if a wildfire with strength $$$1$$$ started at forest $$$1$$$, it would not be able to spread to forest $$$2$$$.
| Name |
|---|


