Histogram Sequence

시간 제한2초메모리 제한1024 MB

요약
히스토그램에서 모든 연속한 막대 구간의 최대 직사각형 넓이를 모아 정렬했을 때, L번째부터 R번째까지의 값을 출력한다.
난이도

어려움10점 중 9점

유형
스택, 이분 탐색, 정렬, 분할 정복
정답자
아직 제출이 없습니다

문제

A histogram is a polygon made by aligning NN adjacent rectangles that share a common base line. Each rectangle is called a bar. The ii-th bar from the left has width 1 and height H_iH\_i.

 

Figure: This picture depicts a case when N=9N = 9 and H=\[7, 4, 3, 5, 4, 2, 5, 1, 2]H = \[7,\ 4,\ 3,\ 5,\ 4,\ 2,\ 5,\ 1,\ 2].

 

One day, you wanted to find the area of the largest rectangle contained in the given histogram. What you did was to make a list of integers AA by the following procedure:

  • For each 1≤i≤j≤N1 \le i \le j \le N, calculate the largest area of the rectangle contained in the histogram, where the rectangle's base line coincides with the base line of the i, i+1, ⋯ , j−1, ji,\ i+1,\ \cdots,\ j-1,\ j-th bar. Add the area to the list AA.

 

Figure: This picture depicts a case when i=3i = 3 and j=5j = 5. The area is 9.

 

The length of the list AA is exactly N(N+1)2\frac{N(N+1)}{2} since you chose each pair (i, j)(i,\ j) exactly once. To make your life easier, you sorted the list AA in non-decreasing order. Now, to find the largest area of the rectangle contained in the histogram, you just need to read the last element of AA, A_N(N+1)/2A\_{N(N+1)/2}.

However, you are not satisfied with this at all, so I decided to let you compute some part of the list AA. You have to write a program that, given two indices LL and RR (L≤RL \le R), calculate the values A_L⋯RA\_{L\cdots R}, i.e. A_L, A_L+1, ⋯ , A_R−1, A_RA\_{L},\ A\_{L+1},\ \cdots,\ A\_{R-1},\ A\_{R}.

입력

The first line of the input contains an integer NN (1≤N≤300,0001 \le N \le 300,000) which is the number of bars in the histogram.

The next line contains NN space-separated positive integers H_1, H_2, ⋯ , H_NH\_1,\ H\_2,\ \cdots,\ H\_N (1≤H_i≤1091 \le H\_i \le 10^9), where H_iH\_i is the height of the ii-th bar.

The last line contains two integers LL and RR (1≤L≤R≤N(N+1)21 \le L \le R \le \frac{N(N+1)}{2}, R−L+1≤300,000R - L + 1 \le 300,000).

출력

Print R−L+1R - L + 1 integers. The jj-th (1≤j≤R−L+11 \le j \le R-L+1) of them should be the (L+j−1)(L+j-1)-th element of the list AA, i.e. A_L+j−1A\_{L+j-1}.

예제1

  1. 예제 1

    입력
    9
    7 4 3 5 4 2 5 1 2
    42 45
    
    예상 출력
    12 12 14 15