Range Sum Query 2D - Mutable
Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper left corner (row1, col1) and lower right corner (row2, col2).
Notice1.The matrix is only modifiable by the update function. 2.You may assume the number of calls to update and sumRegion function is distributed evenly. 3.You may assume that row1 ≤ row2 and col1 ≤ col2.
Example
这题应该用2d binary index tree 或者 2d segementation tree。
用 2d binary index tree 的写法:
2d binary index tree 不太容易想到,但是想通了,写起来很简单,比1d的多一层循环而已
Last updated
Was this helpful?