树状数组用于处理前缀和,单值修改多次询问
每次更新要向右进行更新sum一直到n为止 x += lowbit(x)
每次求和要从底开始向左加所有的sum直到0为止 x -= lowbit(x)
注意:数组要从1开始加
int lowbit(int x){ return x&(-x); } ll sum(int x){ ll sum=0; while(x > 0){ sum = sum+c[x]; x -= lowbit(x); } return sum; } void add(int x,int d){ while(x <= n){ c[x] = c[x]+d; x += lowbit(x); } }