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.
55 lines
1.4 KiB
55 lines
1.4 KiB
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
typedef long long LL;
|
|
const int N = 2050;
|
|
|
|
int n, m;
|
|
LL c1[N][N], c2[N][N], c3[N][N], c4[N][N];
|
|
#define lowbit(x) (x & -x)
|
|
|
|
// 维护四个树状数组
|
|
void add(int x, int y, int v) {
|
|
for (int i = x; i < N; i += lowbit(i))
|
|
for (int j = y; j < N; j += lowbit(j)) {
|
|
c1[i][j] += v;
|
|
c2[i][j] += v * x;
|
|
c3[i][j] += v * y;
|
|
c4[i][j] += v * x * y;
|
|
}
|
|
}
|
|
|
|
// 查询左上角为(1,1)右下角为(x,y)的矩阵和
|
|
LL query(int x, int y) {
|
|
LL res = 0;
|
|
for (int i = x; i; i -= lowbit(i)) {
|
|
for (int j = y; j; j -= lowbit(j)) {
|
|
res += (x + 1) * (y + 1) * c1[i][j];
|
|
res -= (y + 1) * c2[i][j];
|
|
res -= (x + 1) * c3[i][j];
|
|
res += c4[i][j];
|
|
}
|
|
}
|
|
return res;
|
|
}
|
|
|
|
int main() {
|
|
// 加快读入
|
|
ios::sync_with_stdio(false), cin.tie(0);
|
|
cin >> n >> m;
|
|
int op;
|
|
while (cin >> op) {
|
|
int x1, y1, x2, y2;
|
|
cin >> x1 >> y1 >> x2 >> y2;
|
|
if (op == 1) {
|
|
int d;
|
|
cin >> d;
|
|
// 维护四个数组
|
|
add(x1, y1, d);
|
|
add(x1, y2 + 1, -d);
|
|
add(x2 + 1, y1, -d);
|
|
add(x2 + 1, y2 + 1, d);
|
|
} else
|
|
cout << query(x2, y2) - query(x1 - 1, y2) - query(x2, y1 - 1) + query(x1 - 1, y1 - 1) << '\n';
|
|
}
|
|
return 0;
|
|
} |