-
Notifications
You must be signed in to change notification settings - Fork 2
/
q1476.hpp
59 lines (52 loc) · 1.49 KB
/
q1476.hpp
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//
// q1476.hpp
// LeetCode
//
// Created by NowOrNever on 28/08/2020.
// Copyright © 2020 DoubleL. All rights reserved.
//
#ifndef q1476_hpp
#define q1476_hpp
#include <iostream>
#include <queue>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <numeric>
#include <stack>
#include <string>
using namespace std;
void question1476(){
class SubrectangleQueries {
private:
vector<vector<int>> rect;
public:
SubrectangleQueries(vector<vector<int>>& rectangle) {
rect = rectangle;
}
void updateSubrectangle(int row1, int col1, int row2, int col2, int newValue) {
for (int i = row1; i <= row2; i++) {
for (int j = col1; j <= col2; j++) {
rect[i][j] = newValue;
}
}
}
int getValue(int row, int col) {
return rect[row][col];
}
};
// Your SubrectangleQueries object will be instantiated and called as such:
vector<vector<int>> rectangle = {{1,2,1},{4,3,4},{3,2,1},{1,1,1}};
SubrectangleQueries* obj = new SubrectangleQueries(rectangle);
cout << obj->getValue(0, 2) << endl;
obj->updateSubrectangle(0, 0, 3, 2, 5);
cout << obj->getValue(0, 2) << endl;
cout << obj->getValue(3, 1) << endl;
obj->updateSubrectangle(3, 0, 3, 2, 10);
cout << obj->getValue(3, 1) << endl;
cout << obj->getValue(0, 2) << endl;
cout << endl;
}
#endif /* q1476_hpp */