Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/65536 K (Java/Others)
Total Submission(s): 975 Accepted Submission(s): 420
1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<string.h> 4 #define maxn 1005 5 #define lowbit(x) ((x)&(-x)) 6 int aa[maxn][maxn]; 7 bool bb[maxn][maxn]; 8 9 void ope(int x,int y,int val) 10 { 11 int j; 12 if(val==1) 13 { 14 if(bb[x][y]) return ; 15 bb[x][y]=true; 16 } 17 else 18 { 19 if(bb[x][y]==false) 20 return ; 21 bb[x][y]=false; 22 } 23 while(x<maxn){ 24 j=y; 25 while(j<maxn){ 26 aa[x][j]+=val; 27 j+=lowbit(j); 28 } 29 x+=lowbit(x); 30 } 31 } 32 int sum(int x,int y) 33 { 34 int ans=0 ,j; 35 while(x>0){ 36 j=y; 37 while(j>0){ 38 ans+=aa[x][j]; 39 j-=lowbit(j); 40 } 41 x-=lowbit(x); 42 } 43 return ans; 44 } 45 struct node 46 { 47 int x; 48 int y; 49 }; 50 int main() 51 { 52 int test,res; 53 char str[2]; 54 node a,b; 55 memset(aa,0,sizeof(aa)); 56 memset(bb,0,sizeof(bb)); 57 scanf("%d",&test); 58 while(test--) 59 { 60 scanf("%s",str); 61 if(str[0]=='Q') 62 { 63 scanf("%d%d%d%d",&a.x,&b.x,&a.y,&b.y); 64 if(a.x>b.x){ 65 a.x^=b.x; 66 b.x^=a.x; 67 a.x^=b.x; 68 } 69 if(a.y>b.y){ 70 a.y^=b.y; 71 b.y^=a.y; 72 a.y^=b.y; 73 } 74 b.x++; 75 b.y++; 76 res=sum(b.x,b.y)-sum(a.x,b.y)+sum(a.x,a.y)-sum(b.x,a.y); 77 printf("%d\n",res); 78 } 79 else 80 { 81 scanf("%d%d",&a.x,&a.y); 82 a.x++; //ÓÒÒÆһλ 83 a.y++; 84 if(str[0]=='B') 85 ope(a.x,a.y,1); 86 else 87 ope(a.x,a.y,-1); 88 } 89 } 90 return 0; 91 }