#include
using namespace std;
const int max_buf = 4567;
char buf[max_buf], *bufb(buf), *bufe(buf + 1);
#define readBuf() {
if (++ bufb == bufe)
bufe = (bufb = buf) + fread(buf, 1, sizeof(buf), stdin);
}
#define readInt(x) {
register int s(0);
do {
readBuf();
} while (!isdigit(*bufb));
do {
s = s * 10 + *bufb - 48;
readBuf();
} while (isdigit(*bufb));
x = s;
}
struct query { int t, x, y, v; };
const int maxn = 500009; const int maxm = 800009;
int t[maxn], vis[maxn], ans[maxm], tvis, n, m, cq; query q[maxm], b[maxm];
void btChg(int p, int v) { for (; p <= n; p += (p & -p)) if (vis[p] < tvis) vis[p] = tvis, t[p] = v; else t[p] += v; } int btQry(int p) { int s(0); for (; p; p -= (p & -p)) if (vis[p] == tvis) s += t[p]; return s; }
void cdq(query* q, int n) { if (n <= 1) return; int md(n » 1); cdq(q, md); cdq(q + md, n - md); ++ tvis; for (int i = 0, j = md, t = 0; i < md || j < n; ++ t) { if (i == md || (j < n && q[j]. x < q[i]. x)) { b[t] = q[j ++]; if (b[t]. t == 1) ans[b[t]. v] += btQry(b[t]. y); else if (b[t]. t == 2) ans[b[t]. v] -= btQry(b[t]. y); } else { b[t] = q[i ++]; if (b[t]. t == 0) btChg(b[t]. y, b[t]. v); } } for (int i = 0; i < n; ++ i) q[i] = b[i]; }
int main() { #ifndef ONLINE_JUDGE freopen(“in.txt”, “r”, stdin); #endif
readInt(n);
memset(vis, 0, sizeof(vis));
tvis = 0;
m = 0;
cq = 0;
while (1) {
int opt, u, v, p, q;
readInt(opt);
if (opt == 3)
break;
readInt(u);
readInt(v);
if (opt == 1) {
:: q[m]. t = 0;
:: q[m]. x = u;
:: q[m]. y = v;
readInt(:: q[m]. v);
++ m;
}
else {
readInt(p);
readInt(q);
-- u;
-- v;
:: q[m]. t = 1;
:: q[m]. v = cq;
:: q[m]. x = u;
:: q[m]. y = v;
++ m;
:: q[m]. t = 1;
:: q[m]. v = cq;
:: q[m]. x = p;
:: q[m]. y = q;
++ m;
:: q[m]. t = 2;
:: q[m]. v = cq;
:: q[m]. x = u;
:: q[m]. y = q;
++ m;
:: q[m]. t = 2;
:: q[m]. v = cq;
:: q[m]. x = p;
:: q[m]. y = v;
++ m;
ans[cq ++] = 0;
}
}
cdq(q, m);
for (int i = 0; i < cq; ++ i)
printf("%d\n", ans[i]);
}