서로 다른 음높이를 가진 N개 실로폰 막대의 순열을 알아내야 한다. 가장 낮은 음이 가장 높은 음보다 왼쪽에 있고, 구간의 최댓값과 최솟값의 차를 알려주는 질의를 10000번 이내로 쓸 수 있다.
어려움8이분 탐색분할 정복구간완전 탐색아직 제출이 없습니다시간 제한2초메모리 제한512 MBXylophone is a musical instrument which is played by striking wooden bars. A single wooden bar will always sound the same pitch, so a xylophone consists of bars with various pitches.
JOI-kun bought a xylophone consisting of N wooden bars. The bars are lined up in a row and numbered 1 through N from left to right. The bar with number i (1 ≤ i ≤ N) sounds a pitch of height Ai (1 ≤ Ai ≤ N). Different bars sound different pitches. He knows that the bar with the lowest pitch has a smaller number than the bar with the highest pitch.
Because JOI-kun does not know which bar sounds which pitch, he is going to study the pitch of the bars.
JOI-kun has a peculiar sense of sound; when he hears multiple sounds simultaneously, he can tell the difference between the heights of the highest pitch and the lowest pitch. He can strike a lump of bars at a time and hear their sounds. That is, for integers s and t (1 ≤ s ≤ t ≤ N), he can strike the bars with numbers s through t simultaneously, to know the difference between the maximum and the minimum among As, As+1, . . . , At.
He wants determine the pitches of the bars within 10 000 tries of striking.