标签:get gets log sum 树状 div 更新 code 数组
1 int c[MAXN]; 2 int n; 3 4 int lowbit(int x){ 5 return (x&(-x)); 6 } 7 8 void updata(int x,int v){ 9 while(x<=n){//从小到大更新 10 c[i] += v; 11 x += lowbit(x); 12 } 13 } 14 15 int getsum(int x){ 16 int sum = 0; 17 while(x > 0){//从大到小求和 18 sum += c[x]; 19 x -= lowbit(x); 20 } 21 return sum; 22 }
标签:get gets log sum 树状 div 更新 code 数组
原文地址:http://www.cnblogs.com/yZiii/p/7283721.html