Loading...
Loading...
Loading...
A table has R rows and C columns of sales figures. For each query give the sum of the block from row r1, column c1 to row r2, column c2, with all corners included. Rows and columns are numbered from 0.
Example
Input
3 4 3 1 2 4 5 2 0 1 1 6 3 2 2 1 1 2 3 0 0 0 0
Output
14 3
The block sums to 14. The single cell is 3.
Try the problem first. Open one hint at a time.
Build a table of corner totals once, with an extra row and column of zeros.
A block is the big corner, minus the strip above, minus the strip on the left, plus the corner removed twice.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor