const int maxn=1e5+10;
int a[maxn];
int lowbit(int x)
{
return x&(-x);
}
void update(int pos,int plus)
{
while(pos<maxn)
{
a[pos]+=plus;
pos+=lowbit(pos);
}
}
int getsum(int pos)
{
int sum=0;
while(pos>0)
{
sum+=a[pos];
pos-=lowbit(pos);
}
}
int ask(int start,int end)
{
return getsum(end)-getsum(start-1);
}
树状数组板子
最新推荐文章于 2022-10-19 22:16:05 发布