树状数组模板。
#include<bits/stdc++.h> #define int long long #define double long double #define x first #define y second using namespace std; typedef long long LL; typedef long long ll; typedef pair<int, int> PII; const int N = 3e5 + 10; const int M = 1e3 + 10; int mod = 1e9 + 7; ll n, tree[500001]; ll lowbit(ll num) { return num & -num; } void build(ll s, ll num) { for (ll i = s; i <= n; i += lowbit(i)) tree[i] += num; } ll ask(ll s) { ll ans = 0; for (ll i = s; i >= 1; i -= lowbit(i)) ans += tree[i]; return ans; } void solve() { int q; cin >> n >> q; for (int i = 1; i <= n; i++) { int x; cin >> x; build(i, x); } while (q--) { int op, l, x; cin >> op >> l >> x; if (op == 1) { build(l, x); } else { cout << ask(x) - ask(l - 1) << "\n"; } } } signed main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); int _; _ = 1; //cin>>_; while (_--) { solve(); } }