luogu#P4800. [CEOI 2015] 核能国度 (Day2)
[CEOI 2015] 核能国度 (Day2)
Problem Description
Nuclear Country can be seen as a rectangle made of a grid of cells. There are nuclear power plants in Nuclear Country, and each plant occupies one cell. Unfortunately, Nuclear Country has suffered a once-in-a-century major earthquake, causing all nuclear power plants to leak radiation.
The leakage level of each nuclear power plant can be described by two integers . If the plant at explodes, then a cell will receive an additional becquerels of radiation (becquerel is a unit), where is the Chebyshev distance between the two cells, i.e. .
A cell may be affected by radiation leaks from multiple plants.
For example, if a plant with explodes, the cell where it is located will receive becquerels of radiation. The cells with will receive becquerels, and the cells with will receive becquerel.
The environmental agency gives you queries. Each query specifies a rectangle within Nuclear Country. You need to answer: what is the average radiation received (per cell) within that rectangular area.
Input Format
The first line contains two positive integers and , representing the width and height of Nuclear Country.
The second line contains one positive integer , the number of nuclear power plants .
In the next lines, each line contains four positive integers $(1 \leq x_i \leq W, 1 \leq y_i \leq H, 1 \leq a_i,b_i \leq 10^9)$, meaning there is a plant at cell with parameters and . Each cell contains at most one plant.
Line contains one positive integer , the number of queries .
In the next lines, each line contains four positive integers $(1 \leq x_{1j} \leq x_{2j} \leq W, 1 \leq y_{1j} \leq y_{2j} \leq H)$, describing a query rectangle whose top-left corner is and whose bottom-right corner is .
You may assume that the total radiation within Nuclear Country is less than .
Output Format
For each query, output one line with the average radiation over all cells in the given rectangle, rounded to the nearest integer.
4 3
2
1 1 7 3
3 2 4 2
4
1 2 2 3
1 1 4 3
4 2 4 2
1 3 4 3
4
4
2
2
Hint
The following shows the radiation in each cell after two explosions:
7 6 3 2
4 6 5 2
1 3 3 2
-
The total radiation in a square area is , so the average is , which rounds to .
-
The total radiation in the whole Nuclear Country is , so the average is , which rounds to .
-
For a single cell, the average radiation is exactly the radiation it receives.
-
For the last row, the average is , which rounds to .
There are 14 test cases. The odd-numbered test cases contain only plants where is a multiple of . Further limits for each subtask are as follows:
| Test case | Additional constraints | Score |
|---|---|---|
| $N\cdot W \cdot H \leq 10^8,Q \cdot W \cdot H \leq 10^8$ | ||
| There are no explosion events that satisfy the definition of boundary | ||
| None | ||
If a nuclear power plant is on the border of Nuclear Country, or close to the border, its explosion may also affect cells outside Nuclear Country. An explosion that affects cells outside Nuclear Country is called a boundary.
Translated by ChatGPT 5