KthK^{\text{th}} King

시간 제한1초메모리 제한2048 MB

요약
각 k에 대해 길이가 k 이상인 모든 부분배열에서 k번째로 큰 값이 같아지도록 배열을 바꾸는 최소 비용을 구한다.
난이도

어려움10점 중 8점

유형
그리디, 정렬, 수학, 구현
정답자
아직 제출이 없습니다

문제

Samuel recently became the 1st1^{\text{st}} king in the distant country of Reyjrland (pronounced "Ragerland"). He must make sure that the cities represent his likeness as part of the "Inaugural Collection of Preparatory Chores" needed to be done by the king.

Reyjrland can be represented as an array of integers of length nn, corresponding to the values of the nn cities in the country. If we define f(b,k)f(b, k) to be the kthk^\text{th} largest value in an array bb of length at least kk, then the cities are said to represent the kthk^{\text{th}} king's likeness if f(b,k)f(b, k) is the same for all subarrays†^{\dagger} bb of aa which are of length at least kk.

The current values of the cities, aa may not yet represent the king's likeness. To fix this, each day, the king may choose a city and increment or decrement the city's values by 1.

After working for many days inefficiently randomly modifying the values on cities until the array represented his likeness, Samuel swore he would never let future kings go through the same thing. He tasks you to find the minimum number of days to transform the current city values into an array that represents the kthk^{\text{th}} king, for all kk from 11 through nn. Modifications from making the array represent the likeness of the kthk^{\text{th}} king do not carry over to any other king. That is, after each king's reign, the city values are reset to the values in the original array aa.


†^\dagger: An array bb is a subarray of an array aa if bb can be obtained from aa by deleting several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.

입력

The first line of input contains one integer nn (1≤n≤2⋅1051 \le n \le 2\cdot 10^5), the number of cities which is also the length of the array of values.

The next nn lines contain one integer each. The ithi^{\text{th}} line contains a_ia\_i (0≤a_i≤1090 \le a\_i \le 10^9), the value of the ithi^{\text{th}} city.

출력

Output nn lines containing one integer each. The kthk^{\text{th}} line should contain the minimum number of days for the kthk^{\text{th}} king to make the array represent his likeness.

예제2

  1. 예제 1

    입력
    3
    2
    3
    1
    
    예상 출력
    2
    1
    0
    
  2. 예제 2

    입력
    4
    1000000000
    1
    1000000000
    1
    
    예상 출력
    1999999998
    999999999
    0
    0