#P5797. [SEERC 2019] Max or Min
[SEERC 2019] Max or Min
Description
Kevin has integers , arranged in a circular order. On the circle, the numbers and are adjacent, and and are adjacent. Therefore, each number has exactly two adjacent numbers.
In 1 minute, Kevin can change to the minimum or the maximum among these three numbers: and its two adjacent numbers. For example, if and its two adjacent numbers are and , then after changing to the minimum, becomes ; if Kevin changes to the maximum, then is still .
For each integer from to , compute the shortest time to make all numbers on the circle become .
Input Format
The first line contains two integers and $(3 \leq n \leq 2 \cdot 10^5, 1 \leq m \leq 2 \cdot 10^5)$, representing the number of integers on the circle and the range of for which answers are required.
The second line contains integers , representing the numbers on the circle.
Output Format
Output integers. The -th integer is the minimum number of minutes needed to make all numbers on the circle equal to . If it is impossible to make all integers become , output for the -th integer.
7 5
2 5 1 1 2 3 2
5 5 7 -1 6
Hint
To make all integers on the circle become , Kevin needs at least minutes. One feasible sequence of operations is:
- Change to the minimum among it and its adjacent numbers, i.e., change it to .
- Change to the maximum among it and its adjacent numbers, i.e., change it to .
- Change to the maximum among it and its adjacent numbers, i.e., change it to .
- Change to the minimum among it and its adjacent numbers, i.e., change it to .
- Change to the minimum among it and its adjacent numbers, i.e., change it to .
Translated by ChatGPT 5
京公网安备 11011102002149号