-
Notifications
You must be signed in to change notification settings - Fork 3
/
2718.cpp
31 lines (31 loc) · 911 Bytes
/
2718.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
31
class Solution {
public:
long long matrixSumQueries(int n, vector<vector<int>>& queries) {
vector<bool> rowHash(n, false);
vector<bool> columnHash(n, false);
int row = 0;
int column = 0;
int m = queries.size();
long long res = 0;
for (int i = m - 1; i >= 0; --i) {
int type = queries[i][0];
int index = queries[i][1];
int value = queries[i][2];
// row
if (type == 0) {
if (rowHash[index]) continue;
rowHash[index] = true;
row += 1;
res += (n - column) * value;
}
// col
else {
if (columnHash[index]) continue;
columnHash[index] = true;
column += 1;
res += (n - row) * value;
}
}
return res;
}
};