Logo
(追記) (追記ここまで)

17955번 - Max or Min 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 256 MB3391189837.121%

문제

Kevin has n integers a1, a2, . . . , an arranged in a circle. That is, the numbers ai and ai+1 (1 ≤ i < n) are neighbors. The numbers a1 and an are neighbors as well. Therefore, each number has exactly two neighbors.

In one minute, Kevin can set ai to the minimum among three numbers: ai and it’s two neighbors. Alternatively, Kevin can set ai to the maximum among the same numbers. For example, if ai = 5 and ai has two neighbors 3 and 2, and Kevin performs the minimum operation, ai will be equal to 2. However, if he performs the maximum operation, ai will remain 5.

For each x from 1 to m, find the minimum number of minutes to make all numbers equal x, or determine that it is impossible to do so.

입력

The first line contains two integers n and m (3 ≤ n ≤ 2 · 105, 1 ≤ m ≤ 2 · 105) — the number of integers in the circle, and the number of integers you need to find answers for.

The second line contains n integers a1, a2, . . . , an (1 ≤ ai ≤ m) — the integers in the circle.

출력

Print m integers. The i-th integer should be equal to the minimum number of minutes that are needed to make all numbers equal i or −1 if it’s impossible.

제한

예제 입력 1

7 5
2 5 1 1 2 3 2

예제 출력 1

5 5 7 -1 6

노트

To make all numbers equal 2 Kevin needs at least 5 minutes. One of the possible sequence of operations:

  1. Apply min operation to a6, it will be equal to 2.
  2. Apply max operation to a4, it will be equal to 2.
  3. Apply max operation to a3, it will be equal to 5.
  4. Apply min operation to a2, it will be equal to 2.
  5. Apply min operation to a3, it will be equal to 2.

출처

ICPC > Regionals > Europe > Southeastern European Regional Contest > SEERC 2019 A번

Contest > Open Cup > 2019/2020 Season > Stage 6: Grand Prix of Southeastern Europe A번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /