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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
| #include<bits/stdc++.h> using namespace std; typedef long long s64;
const int ONE = 1000005; const int INF = 214748340;
int get() { int res = 1, Q = 1; char c; while( (c = getchar()) < 48 || c > 57) if(c == '-') Q = -1; if(Q) res = c - 48; while( (c = getchar()) >= 48 && c <= 57) res = res * 10 + c - 48; return res * Q; }
int n; namespace BIT { int C[ONE]; int lowbit(int i) {return i & -i;} void Add(int R, int x) { for(int i = R; i <= n; i += lowbit(i)) C[i] += x; } int Query(int R) { int res = 0; for(int i = R; i >= 1; i -= lowbit(i)) res += C[i]; return res; } }
int id, query_num, Ans[ONE]; struct power { int id, opt, from; int x, y, val; }oper[ONE], q[ONE];
bool cmp(const power &a, const power &b) { if(a.x != b.x) return a.x < b.x; return a.opt < b.opt; }
void Deal(int x_1, int y_1, int x_2, int y_2) { query_num++; oper[++id] = (power){id, 2, query_num, x_2, y_2, 1}; oper[++id] = (power){id, 2, query_num, x_1 - 1, y_1 - 1, 1}; oper[++id] = (power){id, 2, query_num, x_1 - 1, y_2, -1}; oper[++id] = (power){id, 2, query_num, x_2, y_1 - 1, -1}; }
void Solve(int l, int r) { if(l >= r) return;
int mid = l + r >> 1; for(int i = l; i <= r; i++) { if(oper[i].opt == 1 && oper[i].id <= mid) BIT::Add(oper[i].y, oper[i].val); if(oper[i].opt == 2 && oper[i].id > mid) Ans[oper[i].from] += BIT::Query(oper[i].y) * oper[i].val; }
for(int i = l; i <= r; i++) if(oper[i].opt == 1 && oper[i].id <= mid) BIT::Add(oper[i].y, -oper[i].val);
int tl = l, tr = mid + 1; for(int i = l; i <= r; i++) if(oper[i].id <= mid) q[tl++] = oper[i]; else q[tr++] = oper[i];
for(int i = l; i <= r; i++) oper[i] = q[i];
Solve(l, mid), Solve(mid + 1, r); }
int opt, x_1, y_1, x_2, y_2;
int main() { n = get(); for(;;) { opt = get(); if(opt == 3) break; if(opt == 1) oper[++id].id = id, oper[id].opt = 1, oper[id].x = get(), oper[id].y = get(), oper[id].val = get(); if(opt == 2) x_1 = get(), y_1 = get(), x_2 = get(), y_2 = get(), Deal(x_1, y_1, x_2, y_2); }
sort(oper + 1, oper + id + 1, cmp);
Solve(1, id);
for(int i = 1; i <= query_num; i++) printf("%d\n", Ans[i]); }
|