二维树状数组(单点修改 区间求和)
1 | long long c[N][N]; |
2 | int n, m; |
3 | int lowbit(int x){ |
4 | return x & -x; |
5 | } |
6 | void update(int x, int y, int w){ |
7 | for(int i = x; i <= n; i += lowbit(i)){ |
8 | for(int j = y; j <= m; j += lowbit(j)) c[i][j] += w; |
9 | } |
10 | } |
11 | long long query(int x, int y){ |
12 | long long res = 0; |
13 | for(int i = x; i; i -= lowbit(i)){ |
14 | for(int j = y; j; j -= lowbit(j)) res += c[i][j]; |
15 | } |
16 | return res; |
17 | } |