stars 第一个树状数组,水过~
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<stdio.h>
2 #include<string.h>
3 #define MAX 32200
4 int c[MAX],level[MAX];
5 int n;
6 int get_val()
7 {
8 int ret(0);
9 char c;
10 while((c=getchar())==''||c=='\n'||c=='\r');
11 ret=c-'0';
12 while((c=getchar())!=''&&c!='\n'&&c!='\r')
13 ret=ret*10+c-'0';
14 return ret;
15 }
16 int lowbit(int x)
17 {
18 return x&(-x);
19 }
20 void update(int x,int num)
21 {
22 while(x<=MAX)
23 {
24 c[x]+=num;
25 x+=lowbit(x);
26 }
27 }
28 int get_sum(int x)
29 {
30 int s=0;
31 while(x>0)
32 {
33 s+=c[x];
34 x-=lowbit(x);
35 }
36 return s;
37 }
38 int main()
39 {
40 int i,x,y;
41 while(~scanf("%d",&n))
42 {
43 memset(c,0,sizeof(c));
44 memset(level,0,sizeof(level));
45 for(i=1;i<=n;i++)
46 {
47 x=get_val();y=get_val();
48 level[get_sum(x+1)]++;
49 update(x+1,1);
50 }
51 for(i=0;i<n;i++)
52 printf("%d\n",level[i]);
53 }
54 return0;
55 }