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.

46 lines
1.0 KiB

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 5000;
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 x1, y1, x2, y2, d;
cin >> x1 >> y1 >> x2 >> y2 >> d;
// 二维差分
add(x1, y1, d);
add(x1, y2 + 1, -d);
add(x2 + 1, y1, -d);
add(x2 + 1, y2 + 1, d);
} else {
int x, y;
cin >> x >> y;
cout << sum(x, y) << '\n';
}
}
return 0;
}