树状数组核心代码

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;
}

原文地址:https://www.cnblogs.com/coded-ream/p/7208022.html