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

<?php



/**
 * Class fenwickTree
 * Fenwick Tree
 * 長さ NN の配列に対し、
 * 1. 要素の 1 点変更
 * 2. 区間の要素の総和
 * を O(logN) で求めることが出来るデータ構造です。
 */
class FenwickTree
{
    private array $tree;
    private int $max;

    /**
     * fenwickTree constructor.
     * @param int $n <10^8
     */
    function __construct(int $n)
    {
        $this->max = $n;
        $this->tree = array_fill(0,$n,0);
    }

    /**
     * a[p] += x を行う 配列はは"0"スタート
     * @param int $p 挿入位置
     * @param int $x 挿入する数
     */
    public function add(int $p, int $x): void
    {
        assert($p >= 0 && $p < $this->max);
        for($i=$p;$i<$this->max; $i |= ($i + 1)){
            $this->tree[$i] += $x;
        }
    }

    /**
     * a[l] + a[l - 1] + ... + a[r - 1] を返す。
     * @param int $l
     * @param int $r
     * @return int
     */
    public function sum(int $l, int $r): int
    {
        assert($l >= 0 && $l <= $r && $r <= $this->max);
        return $this->sum_from_zero($r) - $this->sum_from_zero($l);
    }

    private function sum_from_zero(int $r): int
    {
//        assert($r >= 0 && $r < $this->max);
        $sum = 0;
        for($i = $r - 1; $i >= 0; $i = ($i & ($i + 1)) -1 ){
            $sum += $this->tree[$i];
        }
        return $sum;
    }

}


//使い方
/*
 * https://atcoder.jp/contests/practice2/tasks/practice2_b
 *
 */
[$N, $Q] = fscanf(STDIN, "%d%d");
$A = fscanf(STDIN, str_repeat("%d", $N));
$ft = new FenwickTree($N);
foreach($A as $key=>$value){
    $ft->add($key, $value);
}
while($Q--){
    $que = fscanf(STDIN, "%d%d%d");
    if($que[0] === 0){
        $ft->add($que[1], $que[2]);
    }else{
        echo $ft->sum($que[1], $que[2]) . PHP_EOL;
    }
}