树状数组

时间:2021-04-05 12:05:49   收藏:0   阅读:0
class Sarr
{
public:
	Sarr()
	{
		memset(Bit, 0, sizeof(Bit));
	}
	int lowbit(int pos)
	{
		return pos & (-pos);
	}
	void update(int pos, int len)
	{
		while (pos <= len)
		{
			Bit[pos] += 1;
			pos += lowbit(pos);
		}
	}
	int getSum(int pos)
	{
		int sum = 0;
		while (pos)
		{
			sum += Bit[pos];
			pos -= lowbit(pos);
		}
		return sum;
	}
private:
	int Bit[100010];
}sarr;
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!