forked from doocs/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution.cpp
30 lines (26 loc) · 866 Bytes
/
Solution.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class SubrectangleQueries {
public:
vector<vector<int>> g;
vector<vector<int>> ops;
SubrectangleQueries(vector<vector<int>>& rectangle) {
g = rectangle;
}
void updateSubrectangle(int row1, int col1, int row2, int col2, int newValue) {
ops.push_back({row1, col1, row2, col2, newValue});
}
int getValue(int row, int col) {
for (int i = ops.size() - 1; ~i; --i) {
auto op = ops[i];
if (op[0] <= row && row <= op[2] && op[1] <= col && col <= op[3]) {
return op[4];
}
}
return g[row][col];
}
};
/**
* Your SubrectangleQueries object will be instantiated and called as such:
* SubrectangleQueries* obj = new SubrectangleQueries(rectangle);
* obj->updateSubrectangle(row1,col1,row2,col2,newValue);
* int param_2 = obj->getValue(row,col);
*/