Rectangles

아직 제출이 없습니다시간 제한5초메모리 제한1024 MB

문제

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 n1n-1, and the columns are numbered 00 through m1m-1. We refer to the cell in row ii and column jj (0in1,0jm10 \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 n1n-1, column 00, and column m1m-1). Hence, the architects should choose four integers r_1r\_1, r_2r\_2, c_1c\_1, and c_2c\_2 (1r_1r_2n21 \leq r\_1 \leq r\_2 \leq n-2 and 1c_1c_2m21 \leq c\_1 \leq c\_2 \leq m-2), which define an area consisting of all cells (i,j)(i, j) such that r_1ir_2r\_1 \leq i \leq r\_2 and c_1jc_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_11)(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_11,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).

제한

  • 1n,m25001 \leq n, m \leq 2500
  • 0a\[i]\[j]7,000,0000 \leq a\[i]\[j] \leq 7\\,000\\,000 (for all 0in1,0jm10 \leq i \leq n-1, 0 \leq j \leq m-1)