#P7988. [USACO21DEC] HILO G

[USACO21DEC] HILO G

Problem Description

Bessie has a number x+0.5x+0.5, where xx is an integer between 00 and NN (1N21051\le N\le 2 \cdot 10^5).

Elsie is trying to guess this number. She can ask questions of the following form for some integer between 11 and NN: “Is ii too big or too small?” If ii is greater than x+0.5x+0.5, Bessie answers "HI"; if ii is less than x+0.5x+0.5, she answers "LO".

Elsie comes up with the following strategy to guess Bessie’s number. Before making any guesses, she creates a sequence containing NN integers, where each number from 11 to NN appears exactly once (in other words, the sequence is a permutation of length NN). Then she goes through this list and makes guesses in the order of the numbers in the list.

However, Elsie will skip all unnecessary guesses. That is, if Elsie is about to guess some number ii, but earlier she has already guessed some j<ij < i and Bessie answered "HI", then Elsie will not guess ii and will instead continue to the next number in the sequence. Similarly, if she is about to guess some number ii, but earlier she has already guessed some j>ij > i and Bessie answered "LO", then Elsie will not guess ii and will instead continue to the next number in the sequence. It can be proven that with this strategy, for any sequence Elsie creates, she can uniquely determine xx.

If we concatenate all of Bessie’s answers ("HI" or "LO") into a string SS, then the number of times Bessie says "HILO" is the number of length 44 substrings of SS that are equal to "HILO".

Bessie knows that Elsie will use this strategy; moreover, she also knows the permutation Elsie will use. However, Bessie has not yet decided which value of xx to choose.

Help Bessie compute, for each value of xx, how many times she will say "HILO".

Input Format

The first line contains NN.

The second line contains Elsie’s permutation of length NN.

Output Format

For each xx from 00 to NN, output one line containing the number of times Bessie will say HILO.

5
5 1 2 4 3
0
1
1
2
1
0

Hint

[Sample Explanation]

For x=0x=0, Bessie will say "HIHI", for a total of 00 occurrences of "HILO".

For x=2x=2, Bessie will say "HILOLOHIHI", for a total of 11 occurrence of "HILO".

For x=3x=3, Bessie will say "HILOLOHILO", for a total of 22 occurrences of "HILO".

[Constraints]

  • Testcases 1-4 satisfy N5000N \leq 5000.
  • Testcases 5-8 are uniformly random permutations.
  • Testcases 9-20 have no additional constraints.

Translated by ChatGPT 5