Repovive
  • Dashboard
  • Ranking
  • Submissions
  • Discussion
  1. Contests
  2. Starter Round 8Rated: < 1700
  3. 23E
Sponsor
Abhishek Choudhary

My submissions

/
/
/
/

Announcements

My submissions

/
/
/
/

Announcements

Solve
Author

23E. Louder Every Second

2500 pts·2s·256 MB

Constraints

Input

Output

Samples

Input
4
3 1 1 2
Explanation
Output
0 1 2 1
Input
5
2 1 2 1 4
Explanation
Output
1 2 1 1 0
Input
1
1000000000
Explanation

The only element has no neighbors, so its value never changes.

Output
0

You are given an array of integers a1,a2,…,ana_1,a_2,\ldots,a_na1​,a2​,…,an​.

Every second, the following operation is performed simultaneously for all positions iii:

  • Replace aia_iai​ with max⁡{aj∣max⁡(1,i−1)≤j≤min⁡(n,i+1)}\max\{a_j \mid \max(1,i-1)\le j\le \min(n,i+1)\}max{aj​∣max(1,i−1)≤j≤min(n,i+1)}.

All replacements use the values from the beginning of that second.

For each position, find how many times its value changes before the array stops changing. The initial assignment of values does not count as a change.

  • 1≤n≤2×1051 \le n \le 2 \times 10^51≤n≤2×105
  • 1≤ai≤1091 \le a_i \le 10^91≤ai​≤109
na1a2⋯an\begin{array}{l} n \\ a_1 \quad a_2 \quad \cdots \quad a_n \end{array}na1​a2​⋯an​​
c1c2⋯cnc_1 \quad c_2 \quad \cdots \quad c_nc1​c2​⋯cn​

Here, cic_ici​ is the number of times the value at position iii changes before the array stops changing.

The successive arrays are:

[3,1,1,2]→[3,3,2,2]→[3,3,3,2]→[3,3,3,3][3,1,1,2] \to [3,3,2,2] \to [3,3,3,2] \to [3,3,3,3][3,1,1,2]→[3,3,2,2]→[3,3,3,2]→[3,3,3,3].

The values at positions 111, 222, 333, and 444 change 000, 111, 222, and 111 times, respectively. Position 444 stays unchanged for two seconds before changing to 333.

The successive arrays are:

[2,1,2,1,4]→[2,2,2,4,4]→[2,2,4,4,4]→[2,4,4,4,4]→[4,4,4,4,4][2,1,2,1,4] \to [2,2,2,4,4] \to [2,2,4,4,4] \to [2,4,4,4,4] \to [4,4,4,4,4][2,1,2,1,4]→[2,2,2,4,4]→[2,2,4,4,4]→[2,4,4,4,4]→[4,4,4,4,4].

Position 222 changes from 111 to 222 and later to 444. Both neighboring occurrences of 222 reach it in the first second, but that is only one change. Position 555 never changes, and each remaining position changes once.