PivotOJ

Rectangles

시간 제한: 5000ms메모리 제한: 1024MB출처: IOI 2019BOJ 19916

문제

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 r1r_1, r2r_2, c1c_1, and c2c_2 (1r1r2n21 \leq r_1 \leq r_2 \leq n-2 and 1c1c2m21 \leq c_1 \leq c_2 \leq m-2), which define an area consisting of all cells (i,j)(i, j) such that r1ir2r_1 \leq i \leq r_2 and c1jc2c_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,c11)(i, c_1-1) and cell (i,c2+1)(i, c_2+1)) and the two cells adjacent to the area in column jj (cell (r11,j)(r_1-1, j) and cell (r2+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 r1r_1, r2r_2, c1c_1 and c2c_2 that define a valid area).

코드를 제출하려면 로그인하세요.