You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
822 B
37 lines
822 B
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
|
|
const int N = 5 * 1e5 + 10;
|
|
int n, m;
|
|
int a[N];
|
|
|
|
// 树状数组模板
|
|
typedef long long LL;
|
|
#define lowbit(x) (x & -x)
|
|
int c[N];
|
|
void add(int x, int d) {
|
|
for (int i = x; i < N; i += lowbit(i)) c[i] += d;
|
|
}
|
|
LL sum(int x) {
|
|
LL res = 0;
|
|
for (int i = x; i; i -= lowbit(i)) res += c[i];
|
|
return res;
|
|
}
|
|
|
|
int main() {
|
|
cin >> n >> m;
|
|
for (int i = 1; i <= n; i++)
|
|
cin >> a[i], add(i, a[i]); // 维护进入树状数组,两个概念:位置,值
|
|
|
|
while (m--) {
|
|
int op, x, y;
|
|
cin >> op >> x >> y;
|
|
if (op == 1)
|
|
add(x, y); // 在x位置上加上y
|
|
else
|
|
// 计算[x,y]之间的数字和
|
|
cout << sum(y) - sum(x - 1) << endl;
|
|
}
|
|
return 0;
|
|
} |