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
| #include <cstdio>
using namespace std; using LL = long long; const int N = 4097; int n, m, a, b, c, d; 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", &a, &b, &c); add(a, b, c); } else { scanf("%d%d%d%d", &a, &b, &c, &d); printf("%lld\n", getSum(c, d) - getSum(a - 1, d) - getSum(c, b - 1) + getSum(a - 1, b - 1)); } } return 0; }
|