//预处理
//c[i]=a[i-lowbit(i)+1]+......a[i];
for(int i=1;i<=n;i++)
for(int j=i-lowbit(i)+1;j<=i;j++)
c[i]+=a[j];
//求和
int sum(int x)
{
int ret=0;
while(x>0)
{
ret+=c[x];
x-=lowbit(x);
}
return ret;
}
//更新
void update(int x,int d)
{
while(x<=n)
{
c[x]+=d;
x+=lowbit(x);
}
}
树状数组,二查索引树,BIT
最新推荐文章于 2024-09-11 15:01:00 发布