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 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
| #include <bits/stdc++.h> #define mp make_pair #define pb push_back #define sz(x) (int)x.size() #define all(x) begin(x), end(x) #define fi first #define se second #define debug(x) cerr << #x << " " << x << '\n' using namespace std; using ll = long long; using pii = pair<int,int>; using pli = pair<ll,int>; const int INF = 0x3f3f3f3f, N = 4e5 + 5; const ll LINF = 1e18 + 5; constexpr int mod = 1e9 + 7; int q, c[N], tot, ans[N], id[N]; bool isq[N]; void upd(int x, int v) { for(int i=x; i<=tot; i+=(i&-i)) c[i] += v; } int ask(int x) { int ans = 0; for(int i=x; i>0; i-=(i&-i)) ans += c[i]; return ans; } struct item { int x, y, z, t, coef; bool tag; }p[N], tmp[N], tmp2[N]; bool cmp(item a, item b) { if(a.x==b.x) { if(a.y==b.y) return a.z==b.z ? a.t < b.t : a.z < b.z; return a.y < b.y; } return a.x < b.x; } void CDQ2(int l, int r) { if(l==r) return; int mid = (l+r)>>1; CDQ2(l, mid); CDQ2(mid+1, r); int i = l, j = mid+1, k = l; while(i<=mid&&j<=r) { if(tmp[i].z<=tmp[j].z) { if(!tmp[i].tag&&!tmp[i].coef) upd(tmp[i].t, 1); tmp2[k++] = tmp[i++]; } else { if(tmp[j].tag&&tmp[j].coef) ans[tmp[j].t] += ask(tmp[j].t-1)*tmp[j].coef; tmp2[k++] = tmp[j++]; } } while(i<=mid) { if(!tmp[i].tag&&!tmp[i].coef) upd(tmp[i].t, 1); tmp2[k++] = tmp[i++]; } while(j<=r) { if(tmp[j].tag&&tmp[j].coef) ans[tmp[j].t] += ask(tmp[j].t-1)*tmp[j].coef; tmp2[k++] = tmp[j++]; } for(int i=l; i<=mid; i++) if(!tmp[i].tag&&!tmp[i].coef) upd(tmp[i].t, -1); for(int i=l; i<=r; i++) tmp[i] = tmp2[i]; } void CDQ1(int l, int r) { if(l==r) return; int mid = (l+r)>>1; CDQ1(l, mid); CDQ1(mid+1, r); for(int i=l; i<=mid; i++) p[i].tag = 0; for(int i=mid+1; i<=r; i++) p[i].tag = 1; int i = l, j = mid+1, k = l; while(i<=mid&&j<=r) { if(p[i].y<=p[j].y) tmp[k++] = p[i++]; else tmp[k++] = p[j++]; } while(i<=mid) tmp[k++] = p[i++]; while(j<=r) tmp[k++] = p[j++]; for(int i=l; i<=r; i++) p[i] = tmp[i]; CDQ2(l, r); } void solve() { scanf("%d", &q); tot = 0; for(int i=1; i<=q; i++) { int op; scanf("%d", &op); ans[i] = isq[i] = 0; if(op==1) { int x, y, z; scanf("%d%d%d", &x, &y, &z); p[++tot] = {x, y, z, i, 0}; } else { int x1, y1, z1, x2, y2, z2; scanf("%d%d%d%d%d%d", &x1, &y1, &z1, &x2, &y2, &z2); isq[i] = 1; p[++tot] = {x2, y2, z2, i, 1}; p[++tot] = {x1-1, y2, z2, i, -1}; p[++tot] = {x2, y1-1, z2, i, -1}; p[++tot] = {x2, y2, z1-1, i, -1}; p[++tot] = {x1-1, y1-1, z2, i, 1}; p[++tot] = {x2, y1-1, z1-1, i, 1}; p[++tot] = {x1-1, y2, z1-1, i, 1}; p[++tot] = {x1-1, y1-1, z1-1, i, -1}; } } sort(p+1, p+tot+1, cmp); CDQ1(1, tot); for(int i=1; i<=q; i++) if(isq[i]) printf("%d\n", ans[i]); } int main() { int T; scanf("%d", &T); while(T--) solve(); return 0; }
|