模板
#define lowbit(x) x & -x
//1D
void add(int x,int t) {
while(x <= n) {
v[x] += t;
x += lowbit(x);
}
}
int query(int x) {
int res = 0;
while(x) {
res += v[x];
x -= lowbit(x);
}
return res;
}
//2D n * m
void add(int x,int y,int t) {
while(x <= n) {
for(int k = y;k <= m;k += lowbit(k))
v[x][k] += t;
x += lowbit(x);
}
}
int query(int x,int y) {
int res = 0;
while(x) {
for(int k = y;k;k -= lowbit(k))
res += v[x][k];
x -= lowbit(x);
}
return res;
}
文章评论