传送门biu~
然而在POJ上T了
#include<cstdio>
using namespace std;
#define ll long long
ll a[1<<12+1][1<<12+1];
int n,m;
inline void add(int x,int y,int k){
for(int i=x;i<=n;i+=i&-i)
for(int j=y;j<=m;j+=j&-j)
a[i][j]+=k;
}
inline ll ask(int x,int y){
ll re=0;
for(int i=x;i;i-=i&-i)
for(int j=y;j;j-=j&-j)
re+=a[i][j];
return re;
}
int main(){
scanf("%d%d",&n,&m);
int opt;
while(scanf("%d",&opt)==1){
if(opt==1){
int x,y,k;
scanf("%d%d%d",&x,&y,&k);
add(x,y,k);
}
if(opt==2){
int x1,y1,x2,y2;
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
printf("%lld\n",ask(x2,y2)-ask(x1-1,y2)-ask(x2,y1-1)+ask(x1-1,y1-1));
}
}
}