hdu 1541 树状数组版)——咯咯

/*树状数组版*/ #include<stdio.h> #include<string.h> #define L 32005 #define N 15005 int tree[L]; int count[N]; int n; int lowbit(int x) { return x & (x ^ (x-1)); } int get_sum(int k) { int sum = 0; while(k >=1){ sum += tree[k]; k -= lowbit(k); } return sum; } void tree_insert(int k) { while(k <= L){//这里L写成了,N wa了我三次 tree[k]++; k += lowbit(k); } } int main() { int i; int x,y; while(scanf("%d",&n) == 1){ memset(tree,0,sizeof(tree)); memset(count,0,sizeof(count[0])*n); for(i = 0;i < n;i++){ scanf("%d %d",&x,&y); count[get_sum(x+1)]++; tree_insert(x+1); } for(i = 0;i < n;i++) printf("%d/n",count[i]); } return 0; }

你可能感兴趣的:(tree,insert)