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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
| #include <cstdio> #include <cstring> #include <algorithm> #include <vector> #define X first #define Y second
using namespace std;
typedef long long LL; typedef pair<int, int> pii;
const int maxn = 2005;
char cmd[maxn]; LL bit[maxn][maxn], ans[maxn]; int n, m, a[maxn][maxn]; int u[maxn], l[maxn], d[maxn], r[maxn]; bool vis[maxn][maxn], cur[maxn]; vector<pii> g[maxn];
LL sum(int x, int y) { LL res = 0; for (int i = x; i > 0; i -= i & -i) { for (int j = y; j > 0; j -= j & -j) { res += bit[i][j]; } } return res; }
void add(int x, int y, int d) { for (int i = x; i <= n; i += i & -i) { for (int j = y; j <= m; j += j & -j) { bit[i][j] += d; } } }
int main() { int k; scanf("%d%d%d", &n, &m, &k); for (int i = 1; i <= k; ++i) { int x, y, z; scanf("%d", &z); for (int j = 0 ; j < z; ++j) { scanf("%d%d", &x, &y); g[i].emplace_back(make_pair(x, y)); scanf("%d", &a[x][y]); } } int q, num = 0; scanf("%d", &q); for (int i = 0; i < q; ++i) { scanf("%s", cmd); if (cmd[0] == 'A') { ++num; scanf("%d%d%d%d", &u[num], &l[num], &d[num], &r[num]); for (int j = 1; j <= k; ++j) { vis[j][num] = !cur[j]; } } else { int x; scanf("%d", &x); cur[x] = !cur[x]; } } for (int i = 1; i <= k; ++i) { for (pii& u: g[i]) { add(u.X, u.Y, a[u.X][u.Y]); } for (int j = 1; j <= num; ++j) { if (vis[i][j]) { ans[j] += sum(d[j], r[j]) - sum(d[j], l[j] - 1) - sum(u[j] - 1, r[j]) + sum(u[j] - 1, l[j] - 1); } } for (pii& u: g[i]) { add(u.X, u.Y, -a[u.X][u.Y]); } } for (int i = 1; i <= num; ++i) { printf("%lld\n", ans[i]); } return 0; }
|