树状数组模板

int low_bit(int x)
{
return x&-x;
}
void add(int pos,int val)
{
while(pos<=maxn)
{
c[pos]+=val;
pos+=low_bit(pos);
}
}
int sum(int pos)
{
int ans=0;
while(pos>0)
{
ans+=c[pos];
pos-=low_bit(pos);
}
return ans;
}

原文地址:https://www.cnblogs.com/pengpenggege/p/8457718.html