Build 2D prefix sums for a matrix. Let = sum of submatrix from to .
Formula: . Query : . The and handle inclusion-exclusion: subtract top and left regions, add back the doubly-subtracted corner.
2D prefix sums trace
Build 2D prefix sums for a matrix. Let = sum of submatrix from to .
Formula: . Query : . The and handle inclusion-exclusion: subtract top and left regions, add back the doubly-subtracted corner.