HDU ACM 1541 Stars(树状数组)

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

View Code
 1 #include <iostream>
 2 #include <queue>
 3 using namespace std;
 4 const int MAX = 32000 + 10;
 5 //const int MAXN = 15000 + 10;
 6 int C[MAX];
 7 int Level[MAX];
 8 int n;
 9 int LowBit(int x)
10 {
11     return x & (-x);
12 }
13 void Update(int num)
14 {
15     while(num < MAX)
16     {
17         C[num] += 1;
18         num += LowBit(num);
19     }
20 }
21 int CalSum(int num)
22 {
23     int sum = 0;
24     while(num > 0)
25     {
26         sum += C[num];
27         num -= LowBit(num);
28     }
29     return sum;
30 }
31 
32 int main()
33 {
34     int x,y;
35     while(scanf("%d",&n)!=EOF)
36     {
37         int i;
38         memset(C,0,sizeof(C));
39         memset(Level,0,sizeof(Level));
40         for(i=0;i<n;i++)
41         {
42             scanf("%d%d",&x,&y);
43             Level[CalSum(x+1)]++;
44             Update(x+1);
45         }
46         for(i=0;i<n;i++)
47         {
48             printf("%d\n",Level[i]);
49         }
50     }
51     return 0;
52 }

 

posted @ 2012-11-07 17:19  zx雄  阅读(307)  评论(0编辑  收藏  举报