아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Rectangles

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

요약
직사각형 내부의 모든 셀이 사각형 바깥 같은 행과 열의 네 셀보다 낮아야 할 때, 격자 안쪽에 놓인 유효한 직사각형의 개수를 센다.
난이도

보통10점 중 6점

유형
배열, 누적 합, 구현
정답자
아직 제출이 없습니다

문제

In the early 19th century, the ruler Hoseyngulu Khan Sardar ordered a palace to be built on a plateau overseeing a beautiful river. The plateau is modeled as an n×mn \times m grid of square cells. The rows of the grid are numbered 00 through n−1n-1, and the columns are numbered 00 through m−1m-1. We refer to the cell in row ii and column jj (0≤i≤n−1,0≤j≤m−10 \leq i \leq n-1, 0 \leq j \leq m-1) as cell (i,j)(i,j). Each cell (i,j)(i,j) has a specific height, denoted by a\[i]\[j]a\[i]\[j].

Hoseyngulu Khan Sardar asked his architects to choose a rectangular area to build the palace. The area should not contain any cell from the grid boundaries (row 00, row n−1n-1, column 00, and column m−1m-1). Hence, the architects should choose four integers r_1r\_1, r_2r\_2, c_1c\_1, and c_2c\_2 (1≤r_1≤r_2≤n−21 \leq r\_1 \leq r\_2 \leq n-2 and 1≤c_1≤c_2≤m−21 \leq c\_1 \leq c\_2 \leq m-2), which define an area consisting of all cells (i,j)(i, j) such that r_1≤i≤r_2r\_1 \leq i \leq r\_2 and c_1≤j≤c_2c\_1 \leq j \leq c\_2.

In addition, an area is considered valid, if and only if for every cell (i,j)(i, j) in the area, the following condition holds:

  • Consider the two cells adjacent to the area in row ii (cell (i,c_1−1)(i, c\_1-1) and cell (i,c_2+1)(i, c\_2+1)) and the two cells adjacent to the area in column jj (cell (r_1−1,j)(r\_1-1, j) and cell (r_2+1,j)(r\_2+1, j)).

The height of cell (i,j)(i,j) should be strictly smaller than the heights of all these four cells.

Your task is to help the architects find the number of valid areas for the palace (i.e., the number of choices of r_1r\_1, r_2r\_2, c_1c\_1 and c_2c\_2 that define a valid area).

제한

  •  1≤n,m≤25001 \leq n, m \leq 2500 
  •  0≤a\[i]\[j]≤7,000,0000 \leq a\[i]\[j] \leq 7\\,000\\,000 (for all 0≤i≤n−1,0≤j≤m−10 \leq i \leq n-1, 0 \leq j \leq m-1)

예제

이 문제는 공개된 예제가 없습니다.