A Prefix Sum Array Problem
View as PDFYou are given an grid of integers, with rows numbered from
to
, and columns numbered from
to
. You are also given
queries. Each query consists of
integers:
,
,
, and
, where
represents top-left most cell of a rectangle, and
represents the bottom-right most cell of the rectangle.
Input Specification
The first line of input contains ,
, and
.
The next lines each contain
integers, where the
line contains the integers in the
row of the grid. All integers in the grid are positive and less than or equal to
.
The next lines each contain
integers:
,
,
, and
.
Output Specification
Output lines, where the
line contains the sum of numbers contained within the rectangle described by the
query.
Constraints
Sample Input
5 4 3
2 3 5 8
6 4 8 6
1 4 2 7
4 7 6 5
1 9 1 3
1 1 2 3
2 4 5 4
3 1 5 3
Sample Output
28
21
35
Comments