lowbit(x) = i & -i; 一个数的负数等于这个数的二进制取反+1
一维
void uptree(int i,int val)
{while (i<=n)
{
tree[i]+=val;
i+=i&-i;
}
}
int sum(int i)
{
int s=0;
while (i>0)
{
s+=tree[i];//1~i的区间和
i-=i&-i;
}
return s;
}
二维
void uptree(int x1,int y1,int val)
{
int x=x1;
while (x<=N)
{
int y=y1;
while (y<=N)
{
tree[x][y]+=val;
y+=y&-y;
}
x+=x&-x;
}
}
{
}
int sum(int x1,int y1)
{
int s=0;
int x=x1;
while (x>0)
{
int y=y1;
while (y>0)
{
s+=tree[x][y];
y-=y&-y;
}
x-=x&-x;
}
return s;
}
{
}