P2068 统计和https://www.luogu.com.cn/problem/P2068
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#include <set>
#include <cmath>
#include <map>
#include <cstdlib>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const int MN = 65005;
const int MAXN = 2000010;
const int INF = 0x3f3f3f3f;
#define IOS ios::sync_with_stdio(false)
#define lowbit(x) ((x)&(-x))
int n, w;
ll tree[MAXN];
inline void update(int pos, ll x) {
for (; pos <= n; pos += lowbit(pos)) {
tree[pos] += x;
}
}
inline ll query(int l) {
ll ans = 0;
for (; l; l -= lowbit(l)) {
ans += tree[l];
}
return ans;
}
inline ll query(int l, int r) {
return query(r) - query(l - 1);
}
int main() {
scanf("%d", &n);
scanf("%d", &w);
while (w--) {
char ch;
int a, b;
cin >> ch >> a >> b;
if (ch == 'x') {
update(a, b);
} else {
cout << query(a, b) << '\n';
}
}
return 0;
}