int lowbit(int x)
{
return x&-x;
}
int add(int pos,int a)
{
while (pos<=n)
{
c[pos]+=a;
pos+=lowbit(pos);
}
return 0;
}
int sum(int pos)
{
int ans=0;
while (pos>0)
{
ans+=c[pos];
pos-=lowbit(pos);
}
return ans;
}
树状数组核心代码
最新推荐文章于 2025-02-15 17:14:34 发布