luogu#P10817. [EC Final 2020] Rectangle Flip 2

[EC Final 2020] Rectangle Flip 2

题目描述

Prof. Pang enters a trap room in a dungeon. The room can be represented by an nn by mm chessboard. We use (i,j)(i, j) (1in1\le i\le n, 1jm1\le j\le m) to denote the cell at the ii-th row and jj-th column. Every second, the floor of one cell breaks apart (so that Prof. Pang can no longer stand on that cell.) After nmnm seconds, there will be no cell to stand on and Prof. Pang will fall through to the next (deeper and more dangerous) level.

But Prof. Pang knows that calm is the key to overcome any challenge. So instead of being panic, he calculates the number of rectangles such that every cell in it is intact (i.e., not broken) after every second. (A rectangle represented by four integers a,b,ca, b, c and dd (1abn,1cdm1\le a\le b\le n, 1\le c\le d\le m) includes all cells (i,j)(i, j) such that aib,cjda\le i\le b, c\le j\le d. There are n(n+1)2×m(m+1)2 \frac{n(n+1)}{2} \times \frac{m(m+1)}{2} rectangles in total.)

输入格式

The first line contains two integers nn, mm (1n,m5001\le n, m\le 500) separated by a single space.

The (i+1)(i+1)-th line contains two integers aa, bb separated by a single space representing that the cell (a,b)(a, b) breaks apart at the ii-th second. It is guaranteed that each cell appears exactly once in the input.

输出格式

Output nmnm lines. The ii-th line should contain the number of rectangles such that every cell in it is intact after the first ii cells break apart.

题目大意

题目描述

庞教授进入了一个地下城的陷阱房间。这个房间可以用一个 nnmm 列的棋盘来表示。我们用 (i,j)(i, j) (1in1\le i\le n, 1jm1\le j\le m) 来表示第 ii 行第 jj 列的单元格。每秒钟,有一个单元格的地板会破裂(这样庞教授就不能再站在这个单元格上了)。经过 nmnm 秒后,将没有单元格可供站立,庞教授将跌落到下一个(更深且更危险的)层级。

但庞教授知道冷静是克服任何挑战的关键。因此,他没有惊慌,而是计算了在每秒钟后,所有单元格都完好的矩形的数量(即,每个单元格在矩形中都没有破裂)。一个矩形由四个整数 a,b,ca, b, cdd (1abn,1cdm1\le a\le b\le n, 1\le c\le d\le m) 表示,包含所有 (i,j)(i, j) 使得 aib,cjda\le i\le b, c\le j\le d。总共有 n(n+1)2×m(m+1)2 \frac{n(n+1)}{2} \times \frac{m(m+1)}{2} 个矩形。

输入格式

第一行包含两个整数 nn, mm (1n,m5001\le n, m\le 500),用空格分隔。

(i+1)(i+1) 行包含两个整数 aa, bb,表示在第 ii 秒钟单元格 (a,b)(a, b) 破裂。保证每个单元格在输入中出现恰好一次。

输出格式

输出 nmnm 行。第 ii 行应包含在前 ii 个单元格破裂之后,每个单元格都完好的矩形的数量。

提示

在示例中:在第一秒后,有 33 个面积为 11 的矩形和 22 个面积为 22 的矩形满足条件。因此第一行应该输出 55。在第二秒后,仅第二列中的单元格保持完好。答案应该是 33。在第三秒后,仅一个单元格保持完好。答案应该是 11。在第四秒后,所有单元格都破裂,所以答案应该是 00

翻译者:Immunoglobules

2 2
1 1
2 1
1 2
2 2
5
3
1
0

提示

In the example, after the first second, there are 33 rectangles of area 11 and 22 rectangles of area 22 that satisfy the constraint. So the first line should contain a 55. After the second second, only cells in the second column remains intact. The answer should be 33. After the third second, only one cell remains intact. The answer should be 11. After the fourth second, all cells broke apart so the answer should be 00.