Background
Superbrother in the computer room idle nothing to do (compare his noip, it is ironic ah ...), so bored to start playing "hit the Mole" ...
Describe
In this "hit the Mole" game, the mole will occasionally drill out of the hole, but will not get into the hole (mole really bold ...) )。 The openings are in a square of size n (n<=1024). This square is in a planar Cartesian coordinate system, the lower left corner is (0,0), and the upper-right corner is (n-1,n-1). The location of the hole is the whole point, that is, the horizontal ordinate is an integer. And Superbrother will occasionally want to know the total number of moles in a certain range. This is your mission.
Format
Input format
There are multiple lines for each input file.
The first line, a number n, represents the mole's range.
Each subsequent line has a number m at the beginning, indicating a different operation:
M=1, then followed by 3 numbers x,y,k (0<=x,y
#include <cstdio> using namespace std;
int n,f[1030][1030]={0},m;
int read () {int x=0,f=1;
Char Ch=getchar ();
while (ch< ' 0 ' && ch> ' 9 ') {if (ch== '-') f=-1;
Ch=getchar ();
} while (ch>= ' 0 ' && ch<= ' 9 ') {x=x*10+ch-' 0 ';
Ch=getchar ();
} return x*f;
} int lowbit (int x) {return x& (-X);}
void Add (int x,int y,int t) {int i,j;
For (I=x;i<=n;i+=lowbit (i)) for (J=y;j<=n;j+=lowbit (j)) f[i][j]+=t;
} int query (int x,int y) {int i,j,ans=0;
For (I=x;i>=1;i-=lowbit (i)) for (J=y;j>=1;j-=lowbit (j)) Ans+=f[i][j];
return ans;
} int main () {int x,y,x1,y1,t;
N=read ();
while (M=read (), m!=3) {if (m==1) {x=read () +1;
Y=read (+1);
T=read ();
Add (x,y,t);
} if (m==2) {x=read () +1; Y=read () +1;
X1=read (+1);
Y1=read (+1);
printf ("%d\n", Query (x1,y1)-query (x-1,y1)-query (x1,y-1) +query (x-1,y-1));
}} return 0; }