Histogram and Blue Rectangles

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

요약
히스토그램의 각 접두사마다 그 안에 완전히 들어가는 가장 큰 직사각형의 넓이를 구한다.
난이도

보통10점 중 6점

유형
스택, 배열
정답자
아직 제출이 없습니다

문제

Consider an integer array aa of length nn where all a_ia\_i are positive. Such an array may be represented as histogram. To draw the histogram, for each ii from 0 to n−1n-1 we draw a blue rectangle with vertices (i,0)(i,0), (i,a_i)(i,a\_i), (i+1,a_i)(i+1,a\_i), (i+1,0)(i+1,0).

The rectangle with the vertices at integer points is called \emph{covered} by the histogram, if the sides are parallel to the coordinate axes, and all the internal points of the rectangle are blue.

For each jj between 1 and nn calculate the maximal area of the rectangle covered by first jj columns of the given histogram.

입력

The first line of the input contains one integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5), the length of the array aa. The second line contains nn integers; the ii-th of those integers represents a_ia\_i (1≤a_i≤1071 \le a\_i \le 10^7).

출력

Print nn integers, each on the new line. ii-th of those integers is the maximal area of the rectangle covered by first ii columns of the given histogram.

예제2

  1. 예제 1

    입력
    5
    1 7 2 3 9
    
    예상 출력
    1
    7
    7
    7
    9
    
  2. 예제 2

    입력
    5
    4 5 3 8 7
    
    예상 출력
    4
    8
    9
    12
    15