// 建树状数组 for (int i = 1; i <= n; i++) { cin >> temp; update(i, temp); }
// 接下来m次操作 int op; int x, y; for (int i = 1; i <= m; i++) { cin >> op >> x >> y; if (op == 1) { update(x, y); } else { cout << query(x, y) << endl; } } return; }
#include<bits/stdc++.h> usingnamespace std; #define endl '\n' typedeflonglong ll; int n, m; ll a[305][305] = {0}; ll tr[305][305][105] = {0};
voiddebug() { return; }
intlowbit(int x) { return x & (-x); }
voidupdate(int x, int y, int c, int k) { for (int i = x; i <= n; i += lowbit(i)) { for (int j = y; j <= m; j += lowbit(j)) { tr[i][j][c] += k; } } }
intgetsum(int x, int y, int c) { int tot = 0; for (int i = x; i > 0; i -= lowbit(i)) { for (int j = y; j > 0; j -= lowbit(j)) { tot += tr[i][j][c]; } } return tot; }
intquery(int x0, int y0, int x2, int y2, int c) { returngetsum(x2, y2, c) - getsum(x0 - 1, y2, c) - getsum(x2, y0 - 1, c) + getsum(x0 - 1, y0 - 1, c); }
voidsolve() { cin >> n >> m;
// 建树状数组 for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cin >> a[i][j]; update(i, j, a[i][j], 1); } }
int q; cin >> q; int x, y, c; int op; for (int i = 1; i <= q; i++) { cin >> op; if (op == 1) { cin >> x >> y >> c; update(x, y, a[x][y], -1); a[x][y] = c; update(x, y, c, 1); } else { int x1, y1, x2, y2; cin >> x1 >> x2 >> y1 >> y2 >> c; cout << query(x1, y1, x2, y2, c) << endl; } } return; }
#include<bits/stdc++.h> usingnamespace std; #define endl '\n' typedeflonglong ll; int n, m; voiddebug() { return; } intlowbit(int x) { return x & (-x); } structP { int tr[2050][2050] = {0}; voidupdate(int x, int y, int k) { while (x <= n) { int a = y; while (a <= m) { tr[x][a] += k; a += lowbit(a); } x += lowbit(x); } }
intgetsum(int x, int y) { int ans = 0; while (x >= 1) { int a = y; while (a >= 1) { ans += tr[x][a]; a -= lowbit(a); } x -= lowbit(x); } return ans; } } my1, my2, my3, my4; // 分别维护tr[i][j],tr[i][j]*i,tr[i][j]*j,tr[i][j]*i*j;
voidupdateall(int x, int y, int k) { my1.update(x, y, k); my2.update(x, y, k * x); my3.update(x, y, k * y); my4.update(x, y, k * x * y); }
intgetsumall(int x, int y) { int ans = 0; ans += my1.getsum(x, y) * (x * y + x + y + 1); ans -= my2.getsum(x, y) * (y + 1); ans -= my3.getsum(x, y) * (x + 1); ans += my4.getsum(x, y); return ans; }
voidsolve() { char op; cin >> op >> n >> m; int a, b, c, d, k; while (cin >> op) { if (op == 'L') { cin >> a >> b >> c >> d >> k; updateall(a, b, k); updateall(a, d + 1, -k); updateall(c + 1, b, -k); updateall(c + 1, d + 1, k); } elseif (op == 'k') { cin >> a >> b >> c >> d; cout << getsumall(c, d) - getsumall(a - 1, d) - getsumall(c, b - 1) + getsumall(a - 1, b - 1) << endl; } } return; }