S不用管它…

cdq分治板子題T_T

## 代碼

``````#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
#define N 200005

int T,s,n,opt,x,y,p,q,v,cnt,acnt,bcnt,pa,pb,tot;
struct hp{int x,y,ty,id,v;}opr[N*4],a[N*4],b[N*4],ch[N*4];
int C[N*10],ans[N];
bool flag[N];

int cmp(hp a,hp b)
{
return a.x<b.x;
}
{
if (!loc) return;
for (int i=loc;i<=n;i+=i&(-i))
C[i]+=val;
}
int query(int loc)
{
int ans=0;
for (int i=loc;i>=1;i-=i&(-i))
ans+=C[i];
return ans;
}
void cdq(int l,int r)
{
if (l>=r) return;
int mid=(l+r)>>1;
cdq(l,mid);

acnt=0;
for (int i=l;i<=mid;++i) a[++acnt]=opr[i];
sort(a+1,a+acnt+1,cmp);
bcnt=0;
for (int i=mid+1;i<=r;++i) b[++bcnt]=opr[i];
sort(b+1,b+bcnt+1,cmp);
pa=pb=1;tot=0;
while (pb<=bcnt)
{
while (pa<=acnt&&a[pa].x<=b[pb].x)
{
if (!a[pa].ty)
{
ch[++tot].x=a[pa].y,ch[tot].v=a[pa].v;
}
++pa;
}
ans[b[pb].id]+=query(b[pb].y)*b[pb].ty;
++pb;
}
for (int i=1;i<=tot;++i)

cdq(mid+1,r);
}
int main()
{
scanf("%d%d",&s,&n);
while (~scanf("%d",&opt))
{
++T;
if (opt==3) break;
if (opt==1)
{
scanf("%d%d%d",&x,&y,&v);
opr[++cnt].x=x,opr[cnt].y=y,opr[cnt].ty=0,opr[cnt].v=v,opr[cnt].id=T;
}
else
{
flag[T]=true;
scanf("%d%d%d%d",&x,&y,&p,&q);
opr[++cnt].x=x-1,opr[cnt].y=y-1,opr[cnt].ty=1,opr[cnt].id=T;
opr[++cnt].x=p,opr[cnt].y=q,opr[cnt].ty=1,opr[cnt].id=T;
opr[++cnt].x=x-1,opr[cnt].y=q,opr[cnt].ty=-1,opr[cnt].id=T;
opr[++cnt].x=p,opr[cnt].y=y-1,opr[cnt].ty=-1,opr[cnt].id=T;
}
}
cdq(1,cnt);
for (int i=1;i<=T;++i)
if (flag[i]) printf("%d\n",ans[i]);
}``````