二维数组在就和(a,b),(c,d) :
a<=c,b<=d getsum(c,d)+getsum(a-1,b-1)-getsum(a-1,d)-getsum(c,b-1)
#include<iostream>
#include<cstring>
using namespace std;
typedef long long ll;
ll sum[1140][1140];
ll size;
void init(ll x)
{
size=x+100;
}
void add(ll x,ll y,ll w)
{
ll i,j;
ll z;
while(x<=size)
{
z=y;
while(z<=size)
{
sum[x][z]+=w;
z+=z&-z;
}
x+=x&-x;
}
}
ll getsum(ll x,ll y)
{
ll ans=0;
while(x)
{
ll t=y;
while(t)
{
ans+=sum[x][t];
t-=t&-t;
}
x-=x&-x;
}
return ans;
}
int main()
{
ll S,X,Y,A;
ll L,B,R,T;
std::ios::sync_with_stdio(false);
memset(sum,0,sizeof(sum));
while(true)
{
cin>>S;
if(S==0)
{
cin>>X;
init(X);
}
else if(S==2)
{
cin>>L>>B>>R>>T;
L++;B++,R++,T++;
cout<<(getsum(R,T)+getsum(L-1,B-1)-getsum(L-1,T)-getsum(R,B-1))<<endl;
}
else if(S==1)
{
cin>>X>>Y>>A;
X++;
Y++;
add(X,Y,A);
}
else if(S==3)
{
break;
}
}
return 0;
}