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 32 33 34 35 36 37 38 39 40 41 42
| #include <cstdio>
using namespace std; using LL = long long; const int N = 4097; int n, m, a, b, c, d, k; LL tree[N][N];
int lowbit(int x) { return x & -x; }
void add(int x, int y, int k) { for (int i = x; i <= n; i += lowbit(i)) for (int j = y; j <= m; j += lowbit(j)) tree[i][j] += k; }
LL getSum(int x, int y) { LL s = 0; for (int i = x; i > 0; i -= lowbit(i)) for (int j = y; j > 0; j -= lowbit(j)) s += tree[i][j]; return s; }
int main() { scanf("%d%d", &n, &m); while (scanf("%d", &a) != EOF) { if (a == 1) { scanf("%d%d%d%d%d", &a, &b, &c, &d, &k); add(a, b, k); add(a, d + 1, -k); add(c + 1, b, -k); add(c + 1, d + 1, k); } else { scanf("%d%d", &a, &b); printf("%lld\n", getSum(a, b)); } } return 0; }
|