#P7136. [THUPC 2021 初赛] 方格游戏
[THUPC 2021 初赛] 方格游戏
Description
Little F and Little H are playing a game. Today, they are playing on an 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 rectangular obstacles on the board. Each rectangular obstacle is described by , , , : all cells from row to row and from column to column 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 .
In each game, Little F picks a non-obstacle cell on the board, and Little H picks another non-obstacle cell . The score of this game is the length of the shortest path from to . Little F needs to compute the sum of scores over all possible games, modulo . Note that two games are considered the same if the two chosen cells are the same, i.e., is equivalent to .
Input Format
The first line contains three integers (), (), and ().
The next lines each contain four positive integers (), (), describing the -th rectangular obstacle. For any two different rectangular obstacles and , it holds that or , and also or .
Output Format
A single line with one positive integer: the sum of scores of all games modulo .
3 3 1
2 2 2 2
64
Hint
Sample Explanation #1
There are pairs with distance .
There are pairs with distance .
There are pairs with distance .
There are pairs with distance .
The total score is .
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
京公网安备 11011102002149号