시간 제한 | 메모리 제한 | 제출 | 정답 | 맞은 사람 | 정답 비율 |
---|---|---|---|---|---|

1 초 | 1024 MB | 15 | 1 | 1 | 8.333% |

Long ago, the people of Nuclearia decided to build several nuclear plants. They prospered for many years, but then a terrible misfortune befell them. The land was hit by an extremely strong earthquake, which caused all the nuclear plants to explode, and radiation began to spread throughout the country. When the people had made necessary steps so that no more radiation would emanate, the Ministry of Environment started to find out how much individual regions were polluted by the radiation. Your task is to write a program that will answer the queries of the Ministry.

**How radiation spreads**

Nuclearia can be viewed as a rectangle consisting of W × H cells. Each nuclear plant occupies one cell and is parametrized by two positive integers: a, which is the amount of radiation caused to the cell where the plant was, and b, which describes how rapidly the caused radiation decreases as we go farther from the plant.

More precisely, the amount of radiation caused to cell C = [x_{C}, y_{C}] by explosion of a plant in cell P = [x_{P}, y_{P}] is max(0, a − b · d(P, C)), where d(P, C) is the distance of the two cells, defined by d(P, C) = max(|x_{P} − x_{C}| , |y_{P} − y_{C}|) (i.e., the minimum number of moves a chess king would travel between them).

The total radiation in a cell is simply the sum of the amounts that individual explosions caused to it.

As an example, consider a plant with a = 7 and b = 3. Its explosion causes 7 units of radiation to the cell it occupies, 4 units of radiation to the 8 adjacent cells, and 1 unit of radiation to the 16 cells whose distance is 2. Note that if this plant is situated on the edge of Nuclearia or one cell away from the edge, then the explosion also affects some cells outside Nuclearia. An explosion that affects cells outside Nuclearia is called boundary. (Actually, we are never interested in what happens outside Nuclearia. We just need this definition in the Grading section below.)

**Queries**

The Ministry of Environment makes several queries about the average-per-cell radiation in a given rectangular region. As great chaos rules in the Ministry, you may make no further assumptions about the queried regions — they may overlap or even repeat.

The description of Nuclearia is read from the standard input. The first line contains two space-separated positive integers W and H (where W ·H ≤ 2 500 000) which stand for the width and height of Nuclearia, respectively. The second line contains a positive integer N, which is the number of exploded plants (1 ≤ N ≤ 200 000). Each of the following N lines contains four positive integers x_{i}, y_{i}, a_{i}, b_{i} (1 ≤ x_{i} ≤ W, 1 ≤ y_{i} ≤ H, 1 ≤ a_{i}, b_{i} ≤ 10^{9}), which describe a plant in cell [x_{i}, y_{i}] with parameters a_{i}, b_{i}. Each cell contains at most one plant.

The following line contains a positive integer Q, which is the number of queries (1 ≤ Q ≤ 200 000). Each of the following Q lines contains four positive integers x_{1j} , y_{1j} , x_{2j} , y_{2j} (1 ≤ x_{1j} ≤ x_{2j} ≤ W and 1 ≤ y_{1j} ≤ y_{2j} ≤ H), which describe a query about the rectangle whose upper-left corner is the cell [x_{1j}, y_{1j}] and lower-right corner is the cell [x_{2j}, y_{2j}].

You can assume that the total radiation in Nuclearia is less than 2^{63}.

For each query, output a line which contains the average-per-cell radiation in the queried region, rounded to the nearest integer (half-integral values are rounded up).

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

The radiation in Nuclearia after the two explosions is as follows.

7 6 3 2 4 6 5 2 1 3 3 2

Note that the first explosion is boundary, while the second one is not. As for the queries:

- The total radiation in the 2-by-2 square is 14, so the average is 14/4 = 3.5, rounded to 4.
- The total radiation in Nuclearia is 44, so the average is 44/12 ≈ 3.67, rounded to 4.
- The average in a single cell is simply the amount of radiation therein.
- The average radiation in the last row is 9/4 = 2.25, rounded to 2.