RT
是普通的树状数组解法,为了防爆我还每个数据都换成long long来着 本地调的时候会少输出一行 但是仔细检查了一下没什么问题这样(对手指
希望dalao可以帮忙解答一下(对手指
#include <bits/stdc++.h>
#define ll long long
#define ln inline
#define lowerbit(x) x & -x
#define saysth ilovekanoforever
using namespace std;
const int N = 5 * 1e5 + 5;
ll n, m, a[N], bit[N];
ln void update(ll i, ll x) {for(int pos = i; pos <= n; pos += lowerbit(pos)) bit[pos] += x; }
ln ll bitplus(ll n) {
ll ans = 0;
for(ll pos = n; pos; pos -= lowerbit(pos)) ans += bit[pos];
return ans;
}
ln ll query(ll l, ll r) {return bitplus(r) - bitplus(l - 1); }
int main() {
scanf("%lld%lld", &n, &m);
for(ll i = 1; i <= m; ++i) {
ll a, b; char k;
scanf("%c%lld%lld", &k, &a, &b);
if(k == 'x') update(a, b);
if(k == 'y') printf("%lld\n", query(a, b));
}
return 0;
}