落谷4514
过关代码如下
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
//#define int long longconst int N = 2050;
int t1[N][N], t2[N][N], t3[N][N], t4[N][N];
int lowbit(int x) { return x & (-x); }
int n, m;
void update(int x, int y, int d) {// 进行更新,每次都会涉及到四个数组的跟新for (int i = x; i <= n; i += lowbit(i)) {for (int j = y; j <= m; j += lowbit(j)) {t1[i][j] += d; t2[i][j] += d * x;t3[i][j] += d * y; t4[i][j] += d * x * y;}}
}int sum(int x, int y) {int ans = 0;for (int i = x; i > 0; i -= lowbit(i)) {for (int j = y; j > 0; j -= lowbit(j)) {ans += t1[i][j] * (x + 1) * (y + 1) - (y + 1) * t2[i][j] - (x + 1) * t3[i][j] + t4[i][j];}}return ans;
}signed main() {char h[5];int a, b, c, d, delta;cin >> h >> n >> m;while (scanf("%s", h) != EOF) {if (h[0] == 'L') {cin >> a >> b >> c >> d >> delta;update(a, b, delta);update(c + 1, d + 1, delta);update(a, d + 1, -delta); update(c + 1, b, -delta);}else {cin >> a >> b >> c >> d;cout << sum(c, d) - sum(c, b - 1) - sum(a - 1, d) + sum(a - 1, b - 1) << endl;}}
}