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) (judge verdict: Accepted)

//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
const long double PI=3.14159265358979323846264338327950;

struct BinaryIndexedTree{
    int N;
    vector<long long> bit;
    //全て0で初期化
    BinaryIndexedTree(int size){
        bit.resize(size+1,0);
        N=size+1;
    }
    //bit[a]に値wを加える。O(log n)
    void add(int a,long long w){
        for(int x=a;x<=N;x+=(x & -x)) bit[x]+=w;
        return;
    }
    //bit[1,a]の和bit[1]+bit[2]+   +bit[a]を求める。 O(log n)
    long long sum(int a){
        long long ret=0;
        for(int x=a;x>0;x-=(x & -x)) ret+=bit[x];
        return ret;
    }

    int lower_bound(int  w) { // a_1 + a_2 + ... + a_x >= w となるような最小の x を求め
        if (w <= 0) {
            return 0;
        } else {
            int x = 0, r = 1;
            while (r < N) r = r << 1;
            for (int len = r; len > 0; len = len >> 1) { // 長さlenは1段下るごとに半分に
                if (x + len < N && bit[x + len] < w) { // 採用するとき
                    w -= bit[x + len];
                    x += len;
                }
            }
            return x + 1;
        }
    }

};

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n,q;
  cin>>n>>q;
  BinaryIndexedTree BIT(n);
  rep(i,n){
    int a;
    cin>>a;
    BIT.add(i+1,a);
  }
  rep(i,q){
    int t,l,r;
    cin>>t>>l>>r;
    if(t==0){
      BIT.add(l+1,r);
    }
    else{
      cout<<BIT.sum(r)-BIT.sum(l)<<'\n';
    }
  }

  return(0);
}