标签:++i name space std == using ace lse add
已知一个数列,你需要进行下面两种操作:
1.将某一个数加上x
2.求出某区间每一个数的和
#include <cstdio>
using namespace std;
int n, m;
int a[500001];
inline int lb(int x)
{
return x & (-x);
}
void add(int x, int k)
{
for (int i = x; i <= n; i += lb(i))
a[i] += k;
}
int sum(int x)
{
int ans = 0;
for (int i = x; i; i -= lb(i))
ans += a[i];
return ans;
}
int main()
{
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++i)
{
int x;
scanf("%d", &x);
add(i, x);
}
for (int i = 1; i <= m; ++i)
{
int op, x, y;
scanf("%d%d%d", &op, &x, &y);
if (op == 1)
add(x, y);
else
printf("%d\n", sum(y) - sum(x - 1));
}
}
标签:++i name space std == using ace lse add
原文地址:https://www.cnblogs.com/xuyixuan/p/9429507.html