#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.

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.