二维树状数组模板(单点更新,区间求和)
const int MAXN = 1050;
int N;
int tree[MAXN][MAXN];
int lowbit(int x)
{
return x&(-x);
}
void Add(int x,int y,int val)
{
for (int i=x ; i<=N ; i+=lowbit(i))
for (int j=y ; j<=N ; j+=lowbit(j))
tree[i][j] += val;
}
int Query(int x,int y)
{
int ans=0;
for (int i=x ; i>0 ; i-=lowbit(i))
for (int j=y ; j>0 ; j-=lowbit(j))
ans += tree[i][j];
return ans;
}
inline void init()
{
memset(tree,0,sizeof tree);
}