Problem:
Score : 100 points

Problem Statement

You are given an array a_0, a_1, ..., a_{N-1} of length N. Process Q queries of the following types.

0 p x: a_p \gets a_p + x

1 l r: Print \sum_{i = l}^{r - 1}{a_i}.

Constraints

1 \leq N, Q \leq 500,000

0 \leq a_i, x \leq 10^9

0 \leq p < N

0 \leq l_i < r_i \leq N

All values in Input are integer.

Input

Input is given from Standard Input in the following format:

N Q
a_0 a_1 ... a_{N - 1}
\textrm{Query}_0
\textrm{Query}_1
:
\textrm{Query}_{Q - 1}

Output

For each query of the latter type, print the answer.

Sample Input 1

5 5
1 2 3 4 5
1 0 5
1 2 4
0 3 10
1 0 5
1 0 3

Sample Output 1

15
7
25
6

Solution in C++ (GCC 9.2.1 with AC Library v1.1) (judge verdict: Accepted)

/// 01:00 08/09/20
/// Author: t_bone_289 (An Immature Programmer.... I'm still developing !!)

#include<bits/stdc++.h>

using namespace std;
#define endl '\n'
typedef long long ll;

class FenwickTree {
private:
    vector<ll> tree;
    ll n{};

    ll cumilativeSum(ll index) {
        ll ans = 0;
        while (index >= 0) {
            ans += this->tree[index];
            decrement(index);
        }
        return ans;
    }

    static void increment(ll &index) {
        index |= (index + 1);
    }

    static void decrement(ll &index) {
        index = (index & (1 + index)) - 1;
    }

    void initializeVector(vector<ll> &v) {
        for (ll i = 0; i < n; i++) {
            this->setIndex(i, v[i]);
        }
    }

    void setSize(ll _n) {
        this->n = _n;
        this->tree.resize(_n);
    }

public:
    explicit FenwickTree(ll _n, ll initialValue = 0) {
        setSize(_n);
        fill(this->tree.begin(), this->tree.end(), initialValue);
    }

    explicit FenwickTree(ll _n, vector<ll> &initialVector) {
        setSize(_n);
        this->initializeVector(initialVector);
    }


    void incrementIndex(ll index, ll value) {
        while (index < n) {
            this->tree[index] += value;
            increment(index);
        }
    }

    void setIndex(ll index, ll value) {
        ll currentValue = this->getValueAtIndex(index);
        ll delta = value - currentValue;
        this->incrementIndex(index, delta);
    }

    void incrementRange(ll start, ll end, ll value) {
        incrementIndex(start, value);
        if (end + 1 < n) {
            incrementIndex(end + 1, -value);
        }
    }

    ll rangeSum(ll start, ll end) {
        ll sumTillEnd = this->cumilativeSum(end);
        ll sumToSubtract = this->cumilativeSum(start - 1);
        ll ans = sumTillEnd - sumToSubtract;
        return ans;
    }

    // update for range update and point query
    ll getValueAtIndex(ll index) {
        return rangeSum(index, index);
    }

};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll n;
    cin >> n;
    ll q;
    cin >> q;
    vector<ll> v(n);
    for (auto &x:v) {
        cin >> x;
    }
    FenwickTree fenwickTree(n, v);
    while (q--) {
        ll t, a, b;
        cin >> t >> a >> b;
        if (!t) {
            fenwickTree.incrementIndex(a, b);
        } else {
            cout << fenwickTree.rangeSum(a, b - 1) << endl;
        }
    }
    return 0;
}