AdvancedRating 1500
Rectangle Sums
Answer queries for the sum of a sub-rectangle (r1, c1)–(r2, c2), 1-based inclusive, using 2-D prefix sums.
Input
r c, the grid, q, then q lines 'r1 c1 r2 c2'.
Output
q lines.
Sample 1
Input
3 3 1 2 3 4 5 6 7 8 9 2 1 1 3 3 2 2 3 3
Output
45 28
Sample 2
Input
1 1 5 1 1 1 1 1
Output
5
Output appears here