Problem:
Range Sum Query

Write a program which manipulates a sequence A = {a1, a2, . . . , an} with the following operations:

add(i, x): add x to ai.

getSum(s, t): print the sum of as, as+1,...,at.

Note that the initial values of ai (i = 1, 2, . . . , n) are 0.

Input

n q
com1 x1 y1
com2 x2 y2
...
comq xq yq

In the first line, n (the number of elements in A) and q (the number of queries) are given. Then, q queries are given where com represents the type of queries. '0' denotes add(xi, yi) and '1' denotes getSum(xi, yi).

Output

For each getSum operation, print the sum in a line.

Constraints

1 ≤ n ≤ 100000

1 ≤ q ≤ 100000

If comi is 0, then 1 ≤ xi ≤ n, 0 ≤ yi ≤ 1000.

If comi is 1, then 1 ≤ xi ≤ n, 1 ≤ yi ≤ n.

Sample Input 1

3 5
0 1 1
0 2 2
0 3 3
1 1 2
1 2 2

Sample Output 1

3
2

Solution in Rust (judge verdict: Accepted)

#[allow(unused_imports)]
use std::io::{stdin, Read, StdinLock};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::{HashSet, HashMap, BinaryHeap};
#[allow(unused_imports)]
use std::vec::Vec;

#[allow(dead_code)]
const INF: i32 = 1000_000_000;
#[allow(dead_code)]
const INFLL: i64 = 1000_000_000_000_000_000;
#[allow(dead_code)]
const EPS: f64 = 1.0e-10;
#[allow(dead_code)]
const MOD: i32 = 1000_000_007;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    #[allow(dead_code)]
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner {cin: cin}
    }

    #[allow(dead_code)]
    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
                    .skip_while(|c| c.is_whitespace())
                    .take_while(|c| !c.is_whitespace())
                    .collect::<String>();
        token.parse::<T>().ok()
    }

    #[allow(dead_code)]
    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}


trait Group {
    /// Data type
    type T: Clone;

    /// Identity function
    fn id() -> Self::T;

    /// Operator: op(a, b) <-> ab in this order
    fn op(a: &Self::T, b: &Self::T) -> Self::T;

    /// Inverse
    fn inverse(a: &Self::T) -> Self::T;
}

struct FenwickTree<G: Group> {
    data: std::vec::Vec<G::T>,
    size: usize
}

#[allow(dead_code)]
impl<G: Group> FenwickTree<G> {
    fn new(n: usize) -> FenwickTree<G> {
        FenwickTree::<G> {
            data: vec![G::id(); n],
            size: n,
        }
    }

    fn operate(&mut self, mut i: usize, val: G::T) {
        while i < self.size {
            self.data[i] = G::op(&self.data[i], &val);
            i |= i + 1;
        }
    }

    /// [0..r]
    fn query1(&self, mut r: i32) -> G::T {
        let mut res = G::id();
        while r >= 0 {
            res = G::op(&res, &self.data[r as usize]);
            r = (r & (r + 1)) - 1;
        }
        res
    }
    /// [l..r)
    fn query(&self, l: i32, r: i32) -> G::T {
        G::op(&self.query1(r - 1), &G::inverse(&self.query1(l - 1)))
    }
}

/// Example: Range Sum
struct RangeSum;
#[allow(dead_code)]
impl Group for RangeSum {
    type T = i32;
    fn id() -> i32 {
        0
    }
    fn op(a: &i32, b: &i32) -> i32 {
        a + b
    }
    fn inverse(a: &i32) -> i32 {
        -a
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    let n: usize = sc.read();
    let q: usize = sc.read();
    let mut bit: FenwickTree<RangeSum> = FenwickTree::new(n);
    for _i in 0..q {
        let com: usize = sc.read();
        let x: i32 = sc.read();
        let y: i32 = sc.read();
        match com {
            0 => bit.operate((x - 1) as usize, y),
            1 => println!("{}", bit.query(x - 1, y)),
            _ => panic!("Invalid Command")
        }
    }
}