1 #include<cstdio> 2 #include<cstring> 3 const int maxn=1024+5; 4 int s[maxn][maxn]; 5 int n; 6 int lowbit(int x) 7 { 8 return x&-x; 9 } 10 long long sum(int x,int y) 11 { 12 long long ret=0; 13 for(int i=x;i>0;i-=lowbit(i)) 14 for(int j=y;j>0;j-=lowbit(j)) 15 ret+=s[i][j]; 16 return ret; 17 } 18 void add(int x,int y,int inc) 19 { 20 for(int i=x;i<=n;i+=lowbit(i)) 21 for(int j=y;j<=n;j+=lowbit(j)) 22 s[i][j]+=inc; 23 } 24 int main() 25 { 26 int com; 27 int a,b,c,d; 28 while(scanf("%d",&com)&&com!=3) 29 { 30 if(com==0) 31 { 32 scanf("%d",&n); 33 memset(s,0,sizeof(s)); 34 } 35 else if(com==1) 36 { 37 scanf("%d%d%d",&a,&b,&c); 38 add(a+1,b+1,c); 39 } 40 else if(com==2) 41 { 42 scanf("%d%d%d%d",&a,&b,&c,&d); 43 long long ans=sum(c+1,d+1)+sum(a,b)-sum(c+1,b)-sum(a,d+1); 44 printf("%lld ",ans); 45 } 46 } 47 return 0; 48 }