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)

use proconio::{input, fastout};
use std::ops::{AddAssign, Sub};

#[derive(Debug)]
pub struct FenwickTree<T> {
    n: usize,
    data: Vec<T>,
}

impl<T> FenwickTree<T>
    where T: Default + Clone,
{
    pub fn new(n: usize) -> Self {
        FenwickTree { n, data: vec![T::default(); n] }
    }
}

impl<T> FenwickTree<T> 
    where T: AddAssign + Sub<Output = T> + Default + Clone + Copy,
{
    pub fn add(&mut self, p: usize, x: T) {
        assert!(p < self.n);
        let mut p = p as isize;
        p += 1;
        while p <= self.n as isize {
            self.data[(p-1) as usize] += x;
            p += p & -p;
        }
    }

    pub fn sum(&self, l: usize, r: usize) -> T {
        assert!(l <= r && r <= self.n);
        self._sum(r) - self._sum(l)
    }

    fn _sum(&self, r: usize) -> T {
        let mut s = T::default();
        let mut r = r as isize;
        while r > 0 {
            s += self.data[(r-1) as usize];
            r -= r & -r;
        }
        s
    }
}

#[fastout]
fn main() {
    input! {
        n: usize,
        q: usize,
        aa: [usize; n],
        queries: [(usize, usize, usize); q],
    }

    let mut tree = FenwickTree::new(n);

    for (i, a) in aa.into_iter().enumerate() {
        tree.add(i, a);
    }

    for (q, l, r) in queries {
        if q == 0 {
            tree.add(l, r);
        } else if q == 1 {
            let ans = tree.sum(l, r);
            println!("{}", ans);
        }
    }
}