#P2154. [SDOI2009] 虔诚的墓主人
[SDOI2009] 虔诚的墓主人
Description
Xiao W is the manager of a newly built cemetery. The cemetery can be regarded as an rectangle. Each lattice point is either planted with an evergreen tree, or is a grave plot that has not yet been assigned.
The local residents are very devout Christians, and they are willing to choose a suitable grave plot for themselves in advance. To show their sincerity to the Lord, they hope their grave plot has a high level of piety.
The piety of a grave plot is defined as the number of crosses centered at this plot. A cross consists of a center grave plot, and exactly evergreen trees immediately above, below, left, and right of it.
Formally, for a grave plot at coordinates , the number of crosses centered at it is the number of sequences of length of ordered pairs $[(x_{1,1},y_{1,1}),\allowbreak(x_{1,2},y_{1,2}),\allowbreak\cdots,(x_{1,k},y_{1,k}),\allowbreak(x_{2,1},y_{2,1}),\allowbreak(x_{2,2},y_{2,2}),\allowbreak\cdots,(x_{2,k},y_{2,k}),\allowbreak(x_{3,1},y_{3,1}),\allowbreak(x_{3,2},y_{3,2}),\allowbreak\cdots,(x_{3,k},y_{3,k}),\allowbreak(x_{4,1},y_{4,1}),\allowbreak(x_{4,2},y_{4,2}),\allowbreak\cdots,(x_{4,k},y_{4,k})]$ that satisfy:
- Each ordered pair corresponds to the coordinates of an evergreen tree.
- and .
- and .
- and .
- and .
Xiao W wants to know the sum of the piety levels of all grave plots in the cemetery.
Input Format
The first line contains two positive integers and , representing the width and length of the cemetery. Therefore, this rectangular cemetery has lattice points, with the lower-left corner at and the upper-right corner at .
The second line contains a positive integer , representing the number of evergreen trees in the cemetery.
From the third line, there are lines. Each line contains two non-negative integers and , representing the coordinates of an evergreen tree. The input guarantees that no two evergreen trees have the same coordinates.
The last line contains a positive integer , as defined in the statement.
Output Format
Output a single non-negative integer, which is the sum of the piety levels over all grave plots in this cemetery. For convenience, output the answer modulo .
5 6
13
0 2
0 3
1 2
1 3
2 0
2 1
2 4
2 5
2 6
3 2
3 3
4 3
5 2
2
6
Hint
In the figure, the number of crosses centered at grave plots and is , so their piety levels are both . The piety level of every other grave plot is .

For of the testdata, .
For of the testdata, .
For of the testdata, ,,,,。
There exists of the testdata such that .
There exists of the testdata such that .
Translated by ChatGPT 5
京公网安备 11011102002149号