| Author: | Pavel Mesenev | Time limit: | 2 sec | |
| Input file: | Standard input | Memory limit: | 256 Mb | |
| Output file: | Standard output |
You are given an n × m grid of integers and q queries. Each query is a rectangle given by its top-left corner (r1, c1) and bottom-right corner (r2, c2) (0 ≤ r1 ≤ r2 ≤ n − 1, 0 ≤ c1 ≤ c2 ≤ m − 1); answer with the sum of every cell in that rectangle, inclusive.
The first line contains three integers n, m and q. Each of the next n lines contains m space-separated integers — the grid. Each of the next q lines contains four integers r1, c1, r2, c2.
Print q lines: the sum of each query rectangle, in order.
1 ≤ n, m, \ n ⋅ m ≤ 4 ⋅ 105
1 ≤ q ≤ 2 ⋅ 105
− 109 ≤ grid[i][j] ≤ 109
Every answer fits into a signed 64-bit integer.
| No. | Standard input | Standard output |
|---|---|---|
| 1 |
|
|
| 2 |
|
|
| 3 |
|
|