Qiuqiqiu  
不管道路多么崎岖坎坷,我永远不停下追逐梦想的脚步!

http://acm.hdu.edu.cn/showproblem.php?pid=2642

View Code
 1 #include <cstdio>
2 #include <cstring>
3 using namespace std;
4
5 const int N=1010,maxn=1001;;
6 char flag[N][N];
7 int c[N][N];
8 int lowbit(int x)
9 {
10 return x&(-x);
11 }
12 int sum(int x,int y)
13 {
14 int cnt=0;
15 for(int i=x;i>0;i-=lowbit(i))
16 for(int j=y;j>0;j-=lowbit(j)) cnt+=c[i][j];
17 return cnt;
18 }
19 int main()
20 {
21 int M;
22 scanf("%d",&M);
23 memset(flag,'D',sizeof(flag));
24 memset(c,0,sizeof(c));
25 while (M--)
26 {
27 char op[2];
28 scanf("%s",op);
29 if (op[0]!='Q')
30 {
31 int x,y;
32 scanf("%d%d",&x,&y);
33 x++; y++;
34 if (flag[x][y]==op[0]) continue;
35 flag[x][y]=op[0];
36 int t = op[0]=='B'?1:-1;
37 for (int i=x;i<=maxn;i+=lowbit(i))
38 for (int j=y;j<=maxn;j+=lowbit(j)) c[i][j]+=t;
39 }
40 else
41 {
42 int x1,y1,x2,y2;
43 scanf("%d%d%d%d",&x1,&x2,&y1,&y2);
44 if(x1>x2) {int t=x1; x1=x2; x2=t;}
45 if(y1>y2) {int t=y1; y1=y2; y2=t;}
46 x1++; x2++; y1++; y2++;
47 int ans=sum(x2,y2)-sum(x1-1,y2)-sum(x2,y1-1)+sum(x1-1,y1-1);
48 printf("%d\n",ans);
49 }
50 }
51 return 0;
52 }

 

posted on 2012-03-26 20:57  Qiuqiqiu  阅读(201)  评论(0编辑  收藏  举报