1 int lowbit(
int x)
2 {
3 return x & (-
x);
4 }
5
6 int sum(
int x)
7 {
8 int ret =
0;
9 while(x >
0)
10 {
11 ret += tmp[x]; x -=
lowbit(x);
12 }
13 return ret;
14 }
15
16 void add(
int x,
int d)
17 {
18 while(x <=
n)
19 {
20 tmp[x] += d; x +=
lowbit(x);
21 }
22 }
23 void init()
24 {
25 for(
int i =
1; i <= n; ++
i)
26 add(i,a[i]);
27 }
转载于:https://www.cnblogs.com/Pos-Proteus/p/5537366.html
相关资源:树状数组算法的描述和代码的实现
转载请注明原文地址: https://mac.8miu.com/read-79237.html