//二维树状数组
const int maxn = 1050;
int c[maxn][maxn];
int n;
int lowbit(int x) {
return x&(-x);
}
//设原始矩阵为matrix,将matrix[x][y]加上val对c矩阵所做的修改
void add(int x, int y, int val) {
int i=y;
while (x<=n) {
y=i;
while (y<=n) {
c[x][y]+=val;
y+=lowbit(y);
}
x+=lowbit(x);
}
}
//求matrix子矩阵的(1,1)到(x,y)的和
int get_sum(int x, int y) {
int i=0,j=y;
while (x>0) {
y=j;
while (y>0) {
i+=c[x][y];
y-=lowbit(y);
}
x-=lowbit(x);
}
return i;
}
//一维树状数组
//计算lowbit
int lowbit(int x) {
return x&(-x);
}
//设原始矩阵为a,将a[i]加上val时对c所做的修改
void add(int i, int val) {
while (i<=n) {
c[i]+=val;
i+=lowbit(i);
}
}
//求前i项元素的和
int get_sum(int i) {
int sum=0;
while (i>0) {
sum+=c[i];
i-=lowbit(i);
}
return sum;
}