You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
974 B
42 lines
974 B
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
|
|
typedef long long LL;
|
|
const int N = 5000; // 2^(12)=4096
|
|
|
|
int n, m;
|
|
|
|
LL c[N][N];
|
|
#define lowbit(x) (x & -x)
|
|
void add(int x, int y, int d) {
|
|
for (int i = x; i < N; i += lowbit(i))
|
|
for (int j = y; j < N; j += lowbit(j))
|
|
c[i][j] += d;
|
|
}
|
|
LL sum(int x, int y) {
|
|
LL res = 0;
|
|
for (int i = x; i; i -= lowbit(i))
|
|
for (int j = y; j; j -= lowbit(j))
|
|
res += c[i][j];
|
|
return res;
|
|
}
|
|
|
|
int main() {
|
|
// 加快读入
|
|
ios::sync_with_stdio(false), cin.tie(0);
|
|
cin >> n >> m;
|
|
int op;
|
|
while (cin >> op) {
|
|
if (op == 1) {
|
|
int x, y, d;
|
|
cin >> x >> y >> d;
|
|
add(x, y, d);
|
|
} else {
|
|
int x1, y1, x2, y2;
|
|
cin >> x1 >> y1 >> x2 >> y2;
|
|
cout << sum(x2, y2) - sum(x1 - 1, y2) - sum(x2, y1 - 1) + sum(x1 - 1, y1 - 1) << '\n';
|
|
}
|
|
}
|
|
return 0;
|
|
}
|