int main(){ vector<vector<int> > matrix = { {3, 0, 1, 4, 2}, {5, 6, 3, 2, 1}, {1, 2, 0, 1, 5}, {4, 1, 0, 1, 7}, {1, 0, 3, 0, 5} }; NumMatrix * m = new NumMatrix(matrix); cout<<m->sumRegion(2,1,4,3)<<endl; cout<<m->sumRegion(1,1,2,2)<<endl; cout<<m->sumRegion(1,2,2,4)<<endl; return 0; }
int main() { #if 0 vector<vector<int>> ma { {3, 0, 1, 4, 2}, {5, 6, 3, 2, 1}, {1, 2, 0, 1, 5}, {4, 1, 0, 1, 7}, {1, 0, 3, 0, 5} }; NumMatrix obj {ma}; cout << obj.sumRegion(2, 1, 4, 3) << endl; obj.update(3, 2, 2); cout << obj.sumRegion(2, 1, 4, 3) << endl; obj.update(2, 2, 2); cout << obj.sumRegion(2, 1, 4, 3) << endl; obj.update(4, 3, 2); cout << obj.sumRegion(2, 1, 4, 3) << endl; #endif #if 1 vector<vector<int>> ma { {0,-5,9,1,-8,5,8,1,1,5}, }; NumMatrix obj {ma}; cout << obj.sumRegion(0, 5, 0, 9) << endl; obj.update(0, 3, -1); cout << obj.sumRegion(0, 3, 0, 6) << endl; obj.update(0, 1, 6); obj.update(0, 9, 3); obj.update(0, 7, 2); cout << obj.sumRegion(0, 4, 0, 7) << endl; obj.update(0, 4, -5); cout << obj.sumRegion(0, 8, 0, 9) << endl; obj.update(0, 7, 8); #endif return 0; }