#5156. Problem 2. HILO
Problem 2. HILO
Problem 2. HILO
USACO 2021 December Contest, Gold
Bessie knows a number where is some integer between to inclusive ().
Elsie is trying to guess this number. She can ask questions of the form "is high or low?" for some integer between and inclusive. Bessie responds by saying "HI" if is greater than , or "LO" if is less than .
Elsie comes up with the following strategy for guessing Bessie's number. Before making any guesses, she creates a list of numbers, where every number from to occurs exactly once (in other words, the list is a permutation of size ). Then she goes through the list, guessing numbers that appear in the list in order.
However, Elsie skips any unnecessary guesses. That is, if Elsie is about to guess some number and Elsie previously guessed some and Bessie responded with "HI", Elsie will not guess and will move on to the next number in the list. Similarly, if she is about to guess some number and she previously guessed some and Bessie responded with "LO", Elsie will not guess and will move on to the next number in the list. It can be proven that using this strategy, Elsie always uniquely determines regardless of the permutation she creates.
If we concatenate all of Bessie's responses of either "HI" or "LO" into a single string , then the number of times Bessie says "HILO" is the number of length substrings of that are equal to "HILO."
Bessie knows that Elsie will use this strategy; furthermore, she also knows the exact permutation that Elsie will use. However, Bessie has not decided on what value of to choose.
Help Bessie determine how many times she will say "HILO" for each value of .
INPUT FORMAT (input arrives from the terminal / stdin):
The first line contains
The second line contains Elsie's permutation of size
OUTPUT FORMAT (print output to the terminal / stdout):
For each from to , inclusive, output the number of times Bessie will say HILO on a new line.
SAMPLE INPUT:
5 5 1 2 4 3
SAMPLE OUTPUT:
0 1 1 2 1 0
For , Bessie will say "HIHI," for a total of zero "HILO"s.
For , Bessie will say "HILOLOHIHI," for a total of one "HILO".
For , Bessie will say "HILOLOHILO", for a total of two "HILO"s.
SCORING: Tests 1 to 4 satisfy .Tests 5 to 8 have a uniformly random permutation.Tests 9 to 20 satisfy no further constraints.
Problem credits: Richard Qi