72 lines
1.6 KiB
C++
72 lines
1.6 KiB
C++
|
#include <bits/stdc++.h>
|
|||
|
using namespace std;
|
|||
|
#define LL long long
|
|||
|
|
|||
|
const int SIZE = 1e6;
|
|||
|
|
|||
|
struct node{
|
|||
|
int l, r;
|
|||
|
LL w; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
};
|
|||
|
|
|||
|
node tree[4*SIZE + 1]; // <20><>4<EFBFBD><34><EFBFBD><EFBFBD>С
|
|||
|
|
|||
|
inline void build(int k, int l, int r) { // k<><6B><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
tree[k].l = l;
|
|||
|
tree[k].r = r;
|
|||
|
if (l == r) { // Ҷ<>ӽڵ<D3BD>
|
|||
|
scanf("%lld", &tree[k].w);
|
|||
|
return;
|
|||
|
}
|
|||
|
int mid = l + r >> 1; // <20>൱<EFBFBD><E0B5B1> (l + r) >> 1 k
|
|||
|
int lc = k << 1, rc = lc | 1;
|
|||
|
build(lc, l, mid); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
build(rc, mid + 1, r); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
tree[k].w = tree[lc].w + tree[rc].w;
|
|||
|
}
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
inline void changePoint(int k, int x, int c) {
|
|||
|
if (tree[k].l == tree[k].r) { // <20>ҵ<EFBFBD>Ҷ<EFBFBD>ӽڵ<D3BD>
|
|||
|
tree[k].w += c;
|
|||
|
return;
|
|||
|
}
|
|||
|
int mid = tree[k].l + tree[k].r >> 1;
|
|||
|
int lc = k << 1, rc = lc | 1;
|
|||
|
if (x <= mid)
|
|||
|
changePoint(lc, x, c);
|
|||
|
else
|
|||
|
changePoint(rc, x, c);
|
|||
|
tree[k].w = tree[lc].w + tree[rc].w;
|
|||
|
}
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѯ
|
|||
|
inline LL queryInterval(int k, int L, int R) {
|
|||
|
if (tree[k].l >= L && tree[k].r <= R)
|
|||
|
return tree[k].w;
|
|||
|
|
|||
|
int mid = tree[k].l + tree[k].r >> 1;
|
|||
|
int lc = k<<1, rc = lc | 1;
|
|||
|
LL ans = 0;
|
|||
|
if (L <= mid)
|
|||
|
ans += queryInterval(lc, L, R);
|
|||
|
if (R > mid)
|
|||
|
ans += queryInterval(rc, L, R);
|
|||
|
return ans;
|
|||
|
}
|
|||
|
|
|||
|
int main() {
|
|||
|
int n, q;
|
|||
|
scanf("%d%d", &n, &q);
|
|||
|
build(1, 1, n);
|
|||
|
for (int i = 1; i <= q; i++) {
|
|||
|
int opt, x, y;
|
|||
|
scanf("%d%d%d", &opt, &x, &y);
|
|||
|
if (opt == 1)
|
|||
|
changePoint(1, x, y);
|
|||
|
if (opt == 2)
|
|||
|
printf("%lld\n", queryInterval(1, x, y));
|
|||
|
}
|
|||
|
return 0;
|
|||
|
}
|