1. 程式人生 > >樹狀陣列 (模板)

樹狀陣列 (模板)

struct szsz
{
	int c[maxn];
	int lowbit(int x)
	{
		return x&(-x);
	} 
	int getadd(int x)
	{
		int ans=0;
		while(x>0)
		{
			ans+=c[x];
			x-=lowbit(x);
		}
		return ans;
	}
	void update(int x,int n,int d)
	{
		while(x<=n)
		{
			c[x]+=d;
			x+=lowbit(x); 
		} 
	}
} T;