//树状数组c[i]表示当前i-lowbit(i)+1至i的和
int lowbit(int x)//表示此数最低位的1在哪
{
return x&-x;
}
void update(int x,int N,int d)//找到父亲就一直加lowbit(i)
{
while(x<=N)
{
c[x]+=d;
x+=lowbit(x);
}
}
int psum(int x)
{
int ans=0;
while(x>0)
{
ans+=c[x];
x-=lowbit(x);
}
return ans;
}
03-31
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交