这题是
bzoj 4066(kdtree)的弱化版,没有强制在线,所以离线乱搞
二维cdq分治(学习cdq分治后的第一题)
//By Richard
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#define rep(x,y,z) for (int x=(y);(x)<=(z);(x)++)
#define per(x,y,z) for (int x=(y);(x)>=(z);(x)--)
#define log2(x) (31-__builtin_clz(x))
#define XX 100001
#define mod 1e9+7
#define inf 0x3f3f3f3f
#define cls(x) memset(x,0,sizeof(x))
#ifdef DEBUG
#define debugdo(X) X
#define debugndo(X)
#define debugout(X) cout<<(#X)<<"="<<(X)<<endl
#else
#define debugdo(X)
#define debugndo(X) X
#define debugout(X)
#endif // debug
#define putarray(x,n) rep(iiii,1,n) printf("%d ",x[iiii])
#define mp make_pair
using namespace std;
typedef pair<int,int> pairs;
typedef long long LL;
/read3.0
template <typename T>
inline void read(T &x){char ch;x=0;bool flag=false;ch=getchar();while (ch>'9'||ch<'0') {ch=getchar();if (ch=='-') flag=true;}while ((ch<='9'&&ch>='0')){x=x*10+ch-'0';ch=getchar();}if (flag) x*=-1;}
template <typename T>
inline void read(T &x,T &y){read(x);read(y);}
/variables&functions
#define lowbit(x) (x&(-x))
int n,tot,T,c[800001],ans[800001],opt;
struct AAA
{
int x,y,id,a,belong;
bool operator<(const AAA &other)const
{
return x==other.x?(y==other.y?id<other.id:y<other.y):x<other.x;
}
}q[800001],temp[800001];
void change(int pos,int x)
{
while (pos<=n)
{
c[pos]+=x;
pos+=lowbit(pos);
}
}
int query(int x)
{
int ret=0;
while (x)
{
ret+=c[x];
x-=lowbit(x);
}
return ret;
}
void solve(int l,int r)
{
if (l==r) return;
int mid=((l+r)>>1);
rep(i,l,r)
{
if ((!q[i].belong)&&q[i].id<=mid) change(q[i].y,q[i].a);
else if ((q[i].belong)&&q[i].id>mid) ans[q[i].belong]+=query(q[i].y)*q[i].a;
}
rep(i,l,r) if ((!q[i].belong)&&q[i].id<=mid) change(q[i].y,-q[i].a);
int l1=l,l2=mid+1;
rep(i,l,r)
{
if (q[i].id<=mid) temp[l1++]=q[i];
else temp[l2++]=q[i];
}
rep(i,l,r) q[i]=temp[i];
solve(l,mid);
solve(mid+1,r);
}
int main()
{
read(n);
while (scanf("%d",&opt)!=EOF&&opt^3)
{
if (opt==1)
{
++tot;
q[tot].id=tot;
read(q[tot].x,q[tot].y);
read(q[tot].a);
}
else
{
int x,y,xx,yy;
read(x,y);
read(xx,yy);
q[++tot].belong=++T,q[tot].id=tot,q[tot].x=x-1,q[tot].y=y-1,q[tot].a=1;
q[++tot].belong=T,q[tot].id=tot,q[tot].x=x-1,q[tot].y=yy,q[tot].a=-1;
q[++tot].belong=T,q[tot].id=tot,q[tot].x=xx,q[tot].y=y-1,q[tot].a=-1;
q[++tot].belong=T,q[tot].id=tot,q[tot].x=xx,q[tot].y=yy,q[tot].a=1;
}
}
sort(q+1,q+tot+1);
solve(1,tot);
rep(i,1,T) printf("%d\n",ans[i]);
return 0;
}