水题,线段树板子(单点修改和区间和)
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
const int N = 1e5 + 7;
ull a[N], tree[N * 4];
void change_tree(int l, int r, int i, int p, int k){
if(l == r){
tree[i] += k;
return;
}
int mid = (l + r) >> 1;
if(mid >= p) change_tree(l, mid, i * 2, p, k);
else change_tree(mid + 1, r, i * 2 + 1, p, k);
tree[i] = tree[i * 2] + tree[i * 2 + 1];
}
ull query_tree(int l, int r, int i, int x, int y){
if(x <= l && y >= r)return tree[i];
ull ans = 0;
int mid = (l + r) >> 1;
if(mid >= x) ans += query_tree(l, mid, i * 2, x, y);
if(mid + 1 <= y) ans += query_tree(mid + 1, r, i * 2 + 1, x, y);
return ans;
}
int main(){
int n, q;
scanf("%d%d", &n, &q);
for(int i = 0;i < q;i ++){
getchar();
char ch;
scanf("%c", &ch);
int x, y;
scanf("%d%d", &x, &y);
if(ch == 'x')
change_tree(1, n, 1, x, y);
else
printf("%lld\n", query_tree(1, n, 1, x, y));
}
return 0;
}