1.lowbit x & (-x)
2.C[x] [x - lowbit(x) + 1 , x]的区间和
用处:l->r的和
eg.25(10) = 11001(2)
① ans += C[25]
② 25 -= lowbit(25)
③ ans += C[24]
④ 24 -= lowbit(24)
⑤ ans += C[16]
⑥ 16 -= lowbit(16) = 0;
C[]修改
对于所有y 若x∈[y - lowbit(y) + 1,y] 则C[y] += v;
[y - lowbit(y) + 1,y]:影响范围
int ask(int x){ int res = 0; while(x) res += c[x], x -= lowbit(x); return res; } void add(int x,int v){ while(x <= n){ c[x] += v; x += lowbit(x); } }
标签:24,25,res,树状,int,lowbit,数组,ans From: https://www.cnblogs.com/CatalinaQ/p/17081965.html