___w @ 2024-06-13 20:39:42
```cpp
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mk make_pair
#define ll long long
#define space putchar(' ')
#define enter putchar('\n')
using namespace std;
typedef vector <int> vi;
typedef pair <int, int> pii;
inline int rd() { int x = 0, f = 1; char c = getchar(); while (!isdigit(c)) f = c == '-' ? -1 : f, c = getchar(); while (isdigit(c)) x = (x<<3)+(x<<1)+(c^48), c = getchar(); return x*f; }
inline ll rdll() { ll x = 0, f = 1; char c = getchar(); while (!isdigit(c)) f = c == '-' ? -1 : f, c = getchar(); while (isdigit(c)) x = (x<<3)+(x<<1)+(c^48), c = getchar(); return x*f; }
template <typename T> inline void write(T x) { if (x < 0) x = -x, putchar('-'); if (x > 9) write(x/10); putchar(x%10+48); }
const int N = 2e5+5;
struct node { int x[2], v, l, r, sum, L[2], R[2]; } t[N], u, v;
int n, cnt, lst, b[N], rt[N];
void upd(int p) {
t[p].sum = t[t[p].l].sum+t[t[p].r].sum+t[p].v;
for (int k:{0, 1}) {
t[p].L[k] = t[p].R[k] = t[p].x[k];
if (t[p].l) t[p].L[k] = min(t[p].L[k], t[t[p].l].L[k]), t[p].R[k] = max(t[p].R[k], t[t[p].l].R[k]);
if (t[p].r) t[p].L[k] = min(t[p].L[k], t[t[p].r].L[k]), t[p].R[k] = max(t[p].R[k], t[t[p].r].R[k]);
}
}
int build(int l, int r, int k) {
int mid = l+r>>1;
nth_element(b+l, b+mid, b+r+1, [=](int x, int y) { return t[x].x[k] < t[y].x[k]; });
int p = b[mid];
if (l < mid) t[p].l = build(l, mid-1, k^1);
if (mid < r) t[p].r = build(mid+1, r, k^1);
return upd(p), p;
}
void recycle(int &p) {
if (!p) return;
b[++cnt] = p;
recycle(t[p].l), recycle(t[p].r);
p = 0;
}
int query(int p) {
if (!p) return 0;
int ans = 0, flag = 0;
for (int k:{0, 1}) flag |= t[p].L[k] < u.x[k] || v.x[k] < t[p].R[k];
if (!flag) return t[p].sum;
for (int k:{0, 1}) if (t[p].L[k] < u.x[k] || v.x[k] < t[p].R[k]) return 0;
flag = 0;
for (int k:{0, 1}) flag |= t[p].x[k] < u.x[k] || v.x[k] < t[p].x[k];
if (!flag) ans = t[p].v;
return ans+query(t[p].l)+query(t[p].r);
}
int main() {
rd();
while (1) {
int op = rd();
if (op == 3) break;
if (op == 1) {
int x = rd()^lst, y = rd()^lst, v = rd()^lst;
t[++n] = {{x, y}, v};
b[cnt = 1] = n;
for (int i = 0; ; ++i) {
if (!rt[i]) { rt[i] = build(1, cnt, 0); break; }
else recycle(rt[i]);
}
}
else {
u.x[0] = rd()^lst, u.x[1] = rd()^lst;
v.x[0] = rd()^lst, v.x[1] = rd()^lst;
lst = 0;
for (int i = 0; i <= 18; ++i) lst += query(rt[i]);
write(lst), enter;
}
}
return 0;
}
```