A template problem for difference matrix, which can be generalized to adding other integers to submatrices, not limited to +1. Performing O(1) operations on the difference matrix leaves traces of adding 1 to the submatrix. Then, using the property that prefix sum and difference are inverse operations, computing the prefix sum of the difference matrix yields the answer.
2D difference and its prefix sum
The prefix sum of a 2D difference refers to the sum of the matrix from (0,0) to (i,j)
Note the size of the difference matrix! It should be one larger than the original matrix in each dimension