#P7136. [THUPC 2021 初赛] 方格游戏

[THUPC 2021 初赛] 方格游戏

Description

Little F and Little H are playing a game. Today, they are playing on an N×MN \times M chessboard. Little H wants to test Little F's math skills, but Little F is naturally not good at math, so he asks you for help. To make it harder, Little H will add PP rectangular obstacles on the board. Each rectangular obstacle is described by UU, DD, LL, RR: all cells from row UU to row DD and from column LL to column RR become obstacles. Little H guarantees that all rectangular obstacles do not intersect each other, and that all non-obstacle cells are mutually reachable directly or indirectly. If two non-obstacle cells share a common edge, then they are directly reachable, and the distance between them is 11.

In each game, Little F picks a non-obstacle cell XX on the board, and Little H picks another non-obstacle cell YY. The score of this game (X,Y)(X, Y) is the length of the shortest path from XX to YY. Little F needs to compute the sum of scores over all possible games, modulo 1,000,000,0071,000,000,007. Note that two games are considered the same if the two chosen cells are the same, i.e., (X,Y)(X, Y) is equivalent to (Y,X)(Y, X).

Input Format

The first line contains three integers NN (1N1,000,000,0001 \le N \le 1,000,000,000), MM (1M1,000,000,0001 \le M \le 1,000,000,000), and PP (0P100,0000 \le P \le 100,000).
The next PP lines each contain four positive integers Ui,DiU_i, D_i (1<UiDi<N1 < U_i \le D_i < N), Li,RiL_i, R_i (1<LiRi<M1 < L_i \le R_i < M), describing the ii-th rectangular obstacle. For any two different rectangular obstacles ii and jj, it holds that Di+1<UjD_i + 1 < U_j or Dj+1<UiD_j + 1 < U_i, and also Ri+1<LjR_i + 1 < L_j or Rj+1<LiR_j + 1 < L_i.

Output Format

A single line with one positive integer: the sum of scores of all games modulo 1,000,000,0071,000,000,007.

3 3 1
2 2 2 2

64

Hint

Sample Explanation #1

There are 88 pairs with distance 11.
There are 88 pairs with distance 22.
There are 88 pairs with distance 33.
There are 44 pairs with distance 44.
The total score is 6464.

Source

From the preliminary round of the 2021 Tsinghua University Programming Contest and Intercollegiate Invitational Contest (THUPC2021).

Resources such as the solution can be found at https://github.com/THUSAAC/THUPC2021-pre.

Translated by ChatGPT 5