`sum` 里的 `m` 是什么鬼(
by 热言热语 @ 2020-05-04 22:15:28
```cpp
int sum(int x)
{
int ans = 0;
while (x)
{
ans += c[m]; //???
m -= lowbit(m); //这、、、
}
return ans;
}
```
by hjx__hjx @ 2020-05-04 22:15:41
m???
by PragmaGCC @ 2020-05-04 22:16:03
```cpp
#include <bits/stdc++.h>
#define lowbit(x) x &(-x)
using namespace std;
int a[500005], c[500005], n, m;
int sum(int x)
{
int ans = 0;
while (x)
{
ans += c[x];
x -= lowbit(x);
}
return ans;
}
void update(int x, int val) // 给第 x 个节点增加 val
{
while (x <= n)
{
c[x] += val;
x += lowbit(x);
}
}
int main(void)
{
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++)
{
scanf("%d", &a[i]);
update(i, a[i]);
}
while (m--)
{
int x, y, k;
int opt;
scanf("%d", &opt);
if (opt == 1)
scanf("%d%d", &x, &k), update(x, k);
else if (opt == 2)
scanf("%d%d", &x, &y), printf("%d\n", sum(y) - sum(x - 1));
}
}
```
by JK_LOVER @ 2020-05-04 22:16:10
要注意啊、加油
by JK_LOVER @ 2020-05-04 22:16:45
眼瞎了(((
by David_H_ @ 2020-05-04 22:17:01