Seeing code.
The portal:http://poj.org/problem?id=2155
//Two dimensional Tree_Array;
//Can sum Left_up's nodes in m * n Matrix;
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
using namespace std;
const int N = 1005;
const int M = 1005;
int Bit[M+5][M+5];
void Insert(int x,int y,int value) {
for(int i = x; i <= M ; i += i & (-i)) {
for(int j = y; j <= M ;j += j & (-j)) {
Bit[i][j] += value;
}
}
}
int Query(int x,int y) {
int ret = 0;
for(int i = x; i ;i -= i & (-i)) {
for(int j = y ; j ; j -= j & (-j)) {
ret += Bit[i][j];
}
}
return ret;
}
void Deal_with(){
int T,n,k;
scanf("%d",&T);
while(T--){
memset(Bit,0,sizeof(Bit));
scanf("%d %d",&n,&k);
char temp_c;
int x1,x2,y1,y2;
for(int i=0;i<k;i++){
getchar();
//Deal '\n';
scanf("%c %d %d",&temp_c,&x1,&y1);
if(temp_c == 'C'){
scanf("%d %d",&x2,&y2);
Insert(x1,y1,1);
Insert(x1,y2+1,1);
Insert(x2+1,y1,1);
Insert(x2+1,y2+1,1);
//Use x2 + 1 and y2 + 1; Just for contain nodes in edge;
}
else {
printf("%d\n",Query(x1,y1)&1);
//Query (x1,y1),If an area contain (x1,y1); it will be a point in left_up of (x1,y1);
//If an area don't contain(x1,y1);it may at left_up or right_down
//and contails two points or four points
}
}
if(T > 0)puts("");
}
}
int main(void) {
//freopen("a.in","r",stdin);
Deal_with();
return 0;
}