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

#![allow(unused_imports, non_snake_case, dead_code)]
use proconio::{
    input, fastout,
    marker::{Chars, Bytes, Usize1}
};

struct FenwikTree {
    size: usize,
    depth: usize,
    tree: Vec<i64>,
}
impl FenwikTree {
    fn new(n: usize) -> Self {
        let size = n;
        let mut v = size;
        let mut tmp = 0;
        while v > 0 {
            tmp += 1;
            v >>= 1
        }
        let depth = tmp;
        let tree = vec![0; size + 1];
        FenwikTree { size, depth, tree }
    }
    fn _bitsum(&self, mut i: usize) -> i64 {
        let mut ret = 0;
        while i > 0 {
            ret += self.tree[i];
            i ^= i & (1 + !i);
        }
        ret
    }
    fn bitsum(&self, l: usize, r: usize) -> i64 {
        self._bitsum(r) - self._bitsum(l)
    }
    fn bitadd(&mut self, mut i: usize, x: i64) {
        i += 1;
        while i <= self.size {
            self.tree[i] += x;
            i += i & (1 + !i);
        }
    }
    fn lower_bound(&self, x: i64) -> usize {
        let mut _sum: i64 = 0;
        let mut pos: usize = 0;
        let mut v: usize = 1 << self.depth;
        for _ in (0..self.depth).rev() {
            let k = pos + v;
            if k <= self.size && _sum + self.tree[k] < x {
                _sum += self.tree[k];
                pos = k;
            }
            v >>= 1;
        }
        pos + 1
    }
}

#[fastout]
fn main() {
    input! {
        N: usize, Q: usize,
        a: [i64; N],
        l: [(usize, usize, usize); Q]
    }
    let mut bit = FenwikTree::new(N);
    for i in 0..N {
        bit.bitadd(i, a[i]);
    }
    for &(t, x, y) in &l {
        if t > 0 {
            println!("{}", bit.bitsum(x, y));
        } else {
            bit.bitadd(x, y as i64);
        }
    }
    // println!("{}", N);
}