1 int n; 2 int a[1005],c[1005]; //对应原数组和树状数组 3 4 int lowbit(int x){ 5 return x&(-x); 6 } 7 8 void updata(int i,int k){ //在i位置加上k 9 while(i <= n){ 10 c[i] += k; 11 i += lowbit(i); 12 } 13 } 14 15 int getsum(int i){ //求A[1 - i]的和 16 int res = 0; 17 while(i > 0){ 18 res += c[i]; 19 i -= lowbit(i); 20 } 21 return res; 22 }
标签:return,树状,int,lowbit,C++,板子,数组 From: https://www.cnblogs.com/cdp1591652208/p/17138922.html