# Stars

Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/65536 K (Java/Others) Total Submission(s): 975    Accepted Submission(s): 420

Problem Description

Yifenfei is a romantic guy and he likes to count the stars in the sky. To make the problem easier,we considerate the sky is a two-dimension plane.Sometimes the star will be bright and sometimes the star will be dim.At first,there is no bright star in the sky,then some information will be given as "B x y" where 'B' represent bright and x represent the X coordinate and y represent the Y coordinate means the star at (x,y) is bright,And the 'D' in "D x y" mean the star at(x,y) is dim.When get a query as "Q X1 X2 Y1 Y2",you should tell Yifenfei how many bright stars there are in the region correspond X1,X2,Y1,Y2. There is only one case.

Input

The first line contain a M(M <= 100000), then M line followed. each line start with a operational character. if the character is B or D,then two integer X,Y (0 <=X,Y<= 1000)followed. if the character is Q then four integer X1,X2,Y1,Y2(0 <=X1,X2,Y1,Y2<= 1000) followed.

Output

For each query,output the number of bright stars in one line.

Sample Input

5 B 581 145 B 581 145 Q 0 600 0 200 D 581 145 Q 0 600 0 200

Sample Output

1 0

Author

teddy

Source

``` 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;
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=='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=='B')
85              ope(a.x,a.y,1);
86           else
87              ope(a.x,a.y,-1);
88         }
89     }
90     return 0;
91 }```

0 条评论

• ### HDUOJ----（1031）Design T-Shirt

Design T-Shirt Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/327...

• ### HDUOJ----2489 Minimal Ratio Tree

Minimal Ratio Tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768...

• ### HDUOJ-----2852 KiKi's K-Number（树状数组+二分）

KiKi's K-Number Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32...

• ### 浙江大学计算机与软件学院2019年保研上机模拟练习

A happy number is defined by the following process: Starting with any positive i...

• ### poj-1207 THE 3n+1 problem

Problems in Computer Science are often classified as belonging to a certain clas...

• ### hdu1026 Ignatius and the Princess I（bfs+路径）

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth...

• ### Codeforces 833E Caramel Clouds

E. Caramel Clouds time limit per test：3 seconds memory limit per test：256 megaby...

• ### leetcode502. IPO

Suppose LeetCode will start its IPO soon. In order to sell a good price of its s...

• ### 图论--2-SAT--POJ Ikki's Story IV - Panda's Trick

liympanda, one of Ikki’s friend, likes playing games with Ikki. Today after mine...

• ### 230B. T-primes （数论）

We know that prime numbers are positive integers that have exactly two distinct ...

### 活动推荐 