代码如下:
int c[MAX];
int cc[MAX][MAX];
int lowbit(int x)
{
return x&(-x);
}
int n;
int getsum(int i)
{
int sum=0;
while(i>0)
{
sum+=a[i];
i-=lowbit(i);
}
return sum;
}
void modify(int x,int k)
{
while(x<=n)
{
a[x]+=k;
x+=lowbit(x);
}
}
int getsum(int i,int j)
{
int sum;
while(i>0)
{
int tmp=j;
while(tmp>0)
{
sum+=cc[i][tmp];
tmp-=lowbit(tmp);
}
i-=lowbit(i);
}
return sum;
}
void modify2(int i,int j,int k)
{
while(i<=n)
{
int tmp=j;
while(tmp<=n)
{
cc[i][tmp]+=k;
tmp+=lowbit(tmp);
}
i+=lowbit(i);
}
}