树状数组

树状数组

int lowbit(int x)

{

return x&(-x);

}

void update(int x,int y) 单点修改

{

while(x<=n)

c[x]+=y,x+=lowbit(x);

}

int sum(int x) 区间求和

{

int res=0;

while(x) res+=c[x],x-=lowbit(x);

return res;

}

感谢各位与信奥一本通的鼎力相助!

原文地址:https://www.cnblogs.com/SeanOcean/p/10975664.html