This is Range Sum Query 2D (two-dimensional) from LeetCode. Given a 2D matrix, handle multiple queries that each ask for the sum of elements in a rectangle defined by its upper-left and lower-right corners.
The 1D (one-dimensional) formula was . For 2D, you need something more sophisticated. Read the problem statement carefully, noting the constraints. Try to identify the recursive structure before looking at the solution.