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 (Python):
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
ips = lambda:input().split()
import collections
import math
import itertools
import heapq as hq
import sys
input=sys.stdin.readline
class FenwickTree():
    def __init__(self,n):
        self.n = n
        self.tree = [0]*(n+1)
    def add(self,idx,a):
        idx+=1
        while idx<=self.n:
            self.tree[idx] +=a
            idx += idx &-idx

    def _sum(self,r):
        ret=0
        r+=1
        while r>0:
            ret+=self.tree[r]
            r-=r&-r
        return ret
    def sum(self,l,r):
        return self._sum(r)-self._sum(l-1)

n,q = ma()
A = lma()
ft = FenwickTree(n)
for i in range(n):
    ft.add(i,A[i])
for i in range(q):
    t,u,v = ma()
    if t==0:
        ft.add(u,v)
    else:
        print(ft.sum(u,v-1))

Solution (Python):
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
ips = lambda:input().split()
import collections
import math
import itertools
import heapq as hq

class FenwickTree():
    def __init__(self,n):
        self.n = n
        self.tree = [0]*(n+1)
    def add(self,idx,a):
        idx+=1
        while idx<=self.n:
            self.tree[idx] +=a
            idx += idx &-idx

    def _sum(self,r):
        ret=0
        r+=1
        while r>0:
            ret+=self.tree[r]
            r-=r&-r
        return ret
    def sum(self,l,r):
        return self._sum(r)-self._sum(l-1)

n,q = ma()
A = lma()
ft = FenwickTree(n)
for i in range(n):
    ft.add(i,A[i])
for i in range(q):
    t,u,v = ma()
    if t==0:
        ft.add(u,v)
    else:
        print(ft.sum(u,v-1))

Solution (Python):
n, q = map(int, input().split())
A = list(map(int, input().split()))
seglen = 1
while seglen <= 2*n:
    seglen *= 2
offset = seglen//2
tree = [0] * seglen

def add(idx, x):
    idx += offset
    tree[idx] += x
    while idx > 1:
        idx //= 2
        tree[idx] = tree[2*idx] + tree[2*idx+1]

def sum_range(l, r):
    l += offset
    r += offset
    ret = 0
    while l < r:
        if l%2 == 1:
            ret += tree[l]
            l += 1
        l //= 2

        if r%2 == 1:
            ret += tree[r-1]
            r -= 1
        r //= 2
    return ret

for idx, a in enumerate(A):
    add(idx, a)

for _ in range(q):
    t, x, y = map(int, input().split())
    if t == 0:
        add(x, y)
    else:
        print(sum_range(x, y))

Solution (Python):
class BIT:
  def __init__(s, n):
    s._n = n
    s.data = [0] * n
  def set(s, L):
    for i in range(len(L)):
      s.add(i, L[i])
  def add(s, p, x):
    p += 1
    while p <= s._n:
      s.data[p - 1] += x
      p += p & -p
  def sum(s, l, r):
    return s.zum(r) - s.zum(l)
  def zum(s, r):
    ans = 0
    while r > 0:
      ans += s.data[r - 1]
      r -= r & -r
    return ans

N, Q = list(map(int, input().split()))
a = list(map(int, input().split()))
Query = [list(map(int, input().split())) for _ in range(Q)]
  
bit = BIT(N)
bit.set(a)
 
for q in Query:
  if q[0] == 0:
    _, p, x = q
    bit.add(p, x)
  else:
    _, l, r = q
    print(bit.zum(r) - bit.zum(l))

Solution (Python):
class BIT:
  def __init__(s, n):
    s._n = n
    s.data = [0] * n
  def add(s, p, x):
    p += 1
    while p <= s._n:
      s.data[p - 1] += x
      p += p & -p
  def sum(s, l, r):
    return s.zum(r) - s.zum(l)
  def zum(s, r):
    ans = 0
    while r > 0:
      ans += s.data[r - 1]
      r -= r & -r
    return ans

N, Q = list(map(int, input().split()))
a = list(map(int, input().split()))
Query = [list(map(int, input().split())) for _ in range(Q)]
  
bit = BIT(N)
for i in range(N):
  bit.add(i, a[i])
 
for q in Query:
  if q[0] == 0:
    _, p, x = q
    bit.add(p, x)
  else:
    _, l, r = q
    print(bit.zum(r) - bit.zum(l))

Solution (Python):
class BIT:
  def __init__(s, n):
    s._n = n
    s.data = [0] * n
  def add(s, p, x):
    p += 1
    while p <= s._n:
      s.data[p - 1] += x
      p += p & -p
  def sum(s, l, r):
    return s.zum(r) - s.zum(l)
  def zum(s, r):
    ans = 0
    while r > 0:
      ans += s.data[r - 1]
      r -= r & -r
    return ans

N, Q = list(map(int, input().split()))
a = list(map(int, input().split()))
Query = [list(map(int, input().split())) for _ in range(Q)]
  
bit = BIT(N)
for i in range(N):
  bit.add(i, a[i])
 
for q in Query:
  if q[0] == 0:
    _, p, x = q
    bit.add(p, x)
  else:
    _, l, r = q
    print(bit.sum(l, r))

Solution (Python):
import sys
input = sys.stdin.readline
class BIT:
    def __init__(self, n):
        self.size = n
        self.tree = [0]*(n+1)
    
    def make(self, list):
        self.tree[1:] = list.copy()
        for i in range(self.size+1):
            j = i + (i & (-i))
            if j < self.size+1:
                self.tree[j] += self.tree[i]
 
    def sum(self, i):
        
        s = 0
        while i>0:
            s += self.tree[i]
            i -= i & -i
        return s
    
    def add(self, i, x):
        i += 1
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    
    def bsearch(self,x):
        le = 0
        ri = 1<<(self.size.bit_length()-1)
        while ri > 0:
            if le+ri <= self.size and self.tree[le+ri]<x:
                x -= self.tree[le+ri]
                le += ri
            ri >>= 1
        return le+1

n,q = map(int,input().split())
a = list(map(int,input().split()))
bit = BIT(n)
bit.make(a)
for i in range(q):
    t,l,r = map(int,input().split())
    if t == 0:
        bit.add(l,r)
    else:
        print(bit.sum(r)-bit.sum(l))

Solution (Python):
class binaryindexedtree():
  def __init__(self,n):
    self.n=n
    self.tree=[0]*n
  def add(self,a,w):
    x=a
    while x<=self.n:
      self.tree[x-1]+=w
      x+=x&(-x)
  def sums(self,a):
    x=a
    S=0
    while x!=0:
      S+=self.tree[x-1]
      x-=x&(-x)
    return S
n,q=map(int,input().split())
a=list(map(int,input().split()))
bit=binaryindexedtree(n)
for i,x in enumerate(a,1):
  bit.add(i,x)
ans=[]
for _ in range(q):
  x,y,z=map(int,input().split())
  if x:ans+=[bit.sums(z)-bit.sums(y)]
  else:bit.add(y+1,z)
print(*ans,sep='\n')

Solution (Python):

n, Q = map(int, input().split())

BIT = [0]*(n+1)


def BIT_query(idx):
    res_sum = 0
    while idx > 0:
        res_sum += BIT[idx]
        idx -= idx&(-idx)
    return res_sum


def BIT_update(idx,x):
    while idx <= n:
        BIT[idx] += x
        idx += idx&(-idx)
    return
  

a = list(map(int, input().split()))

for i, x in enumerate(a):
  BIT_update(i+1, x)
  
for _ in range(Q):
  t, a, b = map(int, input().split())
  if t == 0:
    BIT_update(a+1, b)
  else:
    print(BIT_query(b)-BIT_query(a))

Solution (Python):
def segfunc(x,y):return x+y
ide_ele=0
class segtree():
  def __init__(self,init_val,segfunc=segfunc,ide_ele=ide_ele):
    n=len(init_val)
    self.segfunc=segfunc
    self.ide_ele=ide_ele
    self.num=1<<(n-1).bit_length()
    self.tree=[ide_ele]*2*self.num
    for i in range(n):
      self.tree[self.num+i]=init_val[i]
    for i in range(self.num-1,0,-1):
      self.tree[i]=self.segfunc(self.tree[2*i], self.tree[2*i+1])
  def update(self,k,x):
    k+=self.num
    self.tree[k]+=x
    while k>1:
      self.tree[k>>1]=self.segfunc(self.tree[k],self.tree[k^1])
      k>>=1
  def query(self,l,r):
    res=self.ide_ele
    l+=self.num
    r+=self.num+1
    while l<r:
      if l&1:
        res=self.segfunc(res,self.tree[l])
        l+=1
      if r&1:
        res=self.segfunc(res,self.tree[r-1])
      l>>=1
      r>>=1
    return res
n,q=map(int,input().split())
st=segtree(list(map(int,input().split())))
ans=[]
for _ in range(q):
  x,y,z=map(int,input().split())
  if x:ans+=[st.query(y,z-1)]
  else:st.update(y,z)
print(*ans,sep='\n')

Solution (Python):
import sys

input = sys.stdin.buffer.readline


class SegmentTree:
    ele = 0

    def func(self, a, b):
        return a + b

    
    

    def __init__(self, n):  
        self.n = n
        self.num = 2 ** ((self.n - 1).bit_length())
        self.SEG = [self.ele] * (2 * self.num)

    def search(self, idx):
        return self.SEG[idx + self.num]

    def initialize(self, A):
        for i in range(self.n):
            self.SEG[i + self.num] = A[i]
        for i in range(self.num - 1, 0, -1):
            self.SEG[i] = self.func(self.SEG[2 * i], self.SEG[2 * i + 1])

    def update(self, idx, val):
        idx += self.num
        self.SEG[idx] += val
        idx //= 2
        while idx:
            self.SEG[idx] = self.func(self.SEG[2 * idx], self.SEG[2 * idx + 1])
            idx //= 2

    def query(self, left, right):
        
        resleft = self.ele
        resright = self.ele
        left += self.num
        right += self.num
        while right - left > 0:
            if left % 2 == 1:
                resleft = self.func(resleft, self.SEG[left])
                left += 1
            if right % 2 == 1:
                right -= 1
                resright = self.func(resright, self.SEG[right])
            left //= 2
            right //= 2
        return self.func(resleft, resright)


n, q = map(int, input().split())
ST = SegmentTree(n)
ST.initialize(list(map(int, input().split())))
for _ in range(q):
    s, a, b = map(int, input().split())
    if s:
        print(ST.query(a, b))
    else:
        ST.update(a, b)

Solution (Python):
class SegmentTree:
    ele = 0

    def func(self, a, b):
        return a + b

    
    

    def __init__(self, n):  
        self.n = n
        self.num = 2 ** ((self.n - 1).bit_length())
        self.SEG = [self.ele] * (2 * self.num)

    def search(self, idx):
        return self.SEG[idx + self.num]

    def initialize(self, A):
        for i in range(self.n):
            self.SEG[i + self.num] = A[i]
        for i in range(self.num - 1, 0, -1):
            self.SEG[i] = self.func(self.SEG[2 * i], self.SEG[2 * i + 1])

    def update(self, idx, val):
        idx += self.num
        self.SEG[idx] += val
        idx //= 2
        while idx:
            self.SEG[idx] = self.func(self.SEG[2 * idx], self.SEG[2 * idx + 1])
            idx //= 2

    def query(self, left, right):
        
        resleft = self.ele
        resright = self.ele
        left += self.num
        right += self.num
        while right - left > 0:
            if left % 2 == 1:
                resleft = self.func(resleft, self.SEG[left])
                left += 1
            if right % 2 == 1:
                right -= 1
                resright = self.func(resright, self.SEG[right])
            left //= 2
            right //= 2
        return self.func(resleft, resright)


n, q = map(int, input().split())
A = list(map(int, input().split()))

ST = SegmentTree(n)
ST.initialize(A)
for _ in range(q):
    s, a, b = map(int, input().split())
    if s:
        print(ST.query(a, b))
    else:
        ST.update(a, b)

Solution (Python):
import sys
from collections.abc import Iterable


def read():
    return sys.stdin.buffer.readline().rstrip()


class FenwickTree:
    def __init__(self, arg):
        if isinstance(arg, int):
            self._n = arg
            self._a = [0] * arg
        elif isinstance(arg, Iterable):
            a = list(arg)
            self._n = len(a)
            self._a = [0] * self._n
            self.set(a)

    def set(self, a):
        for i, ai in enumerate(a):
            self.add(i, ai)

    def add(self, i, x):
        i += 1
        while i <= self._n:
            self._a[i - 1] += x
            i += i & -i

    def update(self, i, x):
        self.add(i, x - self.sum(i, i + 1))

    def sum(self, l, r):
        return self._sum(r) - self._sum(l)

    def _sum(self, r):
        s = 0
        while r > 0:
            s += self._a[r - 1]
            r -= r & -r
        return s


def main():
    n, q = map(int, read().split())
    fw = FenwickTree(map(int, read().split()))
    for _ in range(q):
        query = [int(i) for i in read().split()]
        if query[0] == 0:
            fw.add(query[1], query[2])
        else:
            print(fw.sum(query[1], query[2]))


if __name__ == '__main__':
    main()

Solution (Python):
import sys


def read():
    return sys.stdin.buffer.readline().rstrip()


class FenwickTree:
    def __init__(self, n):
        self._n = n
        self._a = [0] * n

    def add(self, i, x):
        i += 1
        while i <= self._n:
            self._a[i - 1] += x
            i += i & -i

    def sum(self, l, r):
        return self._sum(r) - self._sum(l)

    def _sum(self, r):
        s = 0
        while r > 0:
            s += self._a[r - 1]
            r -= r & -r
        return s


def main():
    n, q = map(int, read().split())
    fw = FenwickTree(n)
    for i, ai in enumerate(map(int, read().split())):
        fw.add(i, ai)
    for _ in range(q):
        query = [int(i) for i in read().split()]
        if query[0] == 0:
            fw.add(query[1], query[2])
        else:
            print(fw.sum(query[1], query[2]))


if __name__ == '__main__':
    main()

Solution (Python):
import sys


def read():
    return sys.stdin.buffer.readline().rstrip()


class FenwickTree:
    def __init__(self, n):
        self._n = n
        self._a = [0] * n

    def add(self, i, x):
        i += 1
        while i <= self._n:
            self._a[i - 1] += x
            i += i & -i

    def sum(self, l, r):
        return self._sum(r) - self._sum(l)

    def _sum(self, r):
        s = 0
        while r > 0:
            s += self._a[r - 1]
            r -= r & -r
        return s


def main():
    n, q = map(int, read().split())
    fw = FenwickTree(n)
    for i, ai in enumerate(map(int, read().split())):
        fw.add(i, ai)
    for _ in range(q):
        query = [int(i) for i in read().split()]
        if query[0] == 0:
            fw.add(query[1], query[2])
        else:
            print(fw.sum(query[1], query[2]))


if __name__ == '__main__':
    main()

Solution (Python):
class BIT:
  def __init__(self,n,li):
    self.n = n
    self.el = [0] + li
    self.data = [0]*(n+1)
    for i in range(1,n+1):
      self.data[i] = sum(self.el[i+1-(i&-i):i+1])
  def sum(self,i):
    s = 0
    while i > 0:
      s += self.data[i]
      i -= i & -i
    return s
  def add(self,i,x):
    self.el[i] += x
    while  i <= self.n:
      self.data[i] += x
      i += i & -i
  def get(self,i,j=None):
    if j is None:
      return self.el[i]
    return self.sum(j)-self.sum(i-1)
n,q = map(int,input().split())
a = list(map(int,input().split()))
bt = BIT(n,a)
for _ in range(q):
  i,j,k = map(int,input().split())
  if i == 0:
    bt.add(j+1,k)
  else:
    print(bt.get(j+1,k))

Solution (Python):
class FenwickTree:
    def __init__(self, n):
        self.n = n
        self.bit = [0] * (n + 1)
    
    def build(self, lst):
        self.value = lst
        for i, x in enumerate(lst):
            self.add(i + 1, x)
        
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.bit[i]
            i -= i & -i
        return s
    
    def add(self, i, x):
        while i <= self.n:
            self.bit[i] += x
            i += i & -i
    
    def get_sum(self, i, j):
        return self.sum(j) - self.sum(i)

import sys
input = sys.stdin.readline

N, Q = map(int, input().split())
A = list(map(int, input().split()))

bit = FenwickTree(N)
bit.build(A)

for i in range(Q):
    a, b, c = map(int, input().split())
    if a == 0:
        bit.add(b + 1, c)
    else:
        print(bit.get_sum(b, c))

Solution (Python):
class FenwickTree:
    def __init__(self, n):
        self.n = n
        self.bit = [0] * (n + 1)
    
    def build(self, lst):
        self.value = lst
        for i, x in enumerate(lst):
            self.add(i + 1, x)
        
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.bit[i]
            i -= i & -i
        return s
    
    def add(self, i, x):
        while i <= self.n:
            self.bit[i] += x
            i += i & -i
    
    def get_sum(self, i, j):
        return self.sum(j) - self.sum(i)
    
N, Q = map(int, input().split())
A = list(map(int, input().split()))

bit = FenwickTree(N)
bit.build(A)

for i in range(Q):
    a, b, c = map(int, input().split())
    if a == 0:
        bit.add(b + 1, c)
    else:
        print(bit.get_sum(b, c))

Solution (Python):
import sys
input=sys.stdin.readline
n,q=map(int,input().split())

BIT=[0]*n
def ADD(x,y):
	while x<=n:
		BIT[x-1]+=y
		x+=x&(-x)
def SUM(l):
	ret=0
	while l>=1:
		ret+=BIT[l-1]
		l-=l&(-l)
	return ret

IN=list(map(int,input().split()))
for i in range(n):
	ADD(i+1,IN[i])

for i in range(q):
	t,a,b=map(int,input().split())
	if t==0:
		ADD(a+1,b)
	else:
		print(SUM(b)-SUM(a))

Solution (Python):
import sys
input=sys.stdin.readline
n,q=map(int,input().split())

BIT=[0]*n
def ADD(x,y):
	while x<=n:
		BIT[x-1]+=y
		x+=x&(-x)
def SUM(l):
	if l==0:
		return 0
	ret=0
	while l>=1:
		ret+=BIT[l-1]
		l-=l&(-l)
	return ret

IN=list(map(int,input().split()))
for i in range(n):
	ADD(i+1,IN[i])

for i in range(q):
	t,a,b=map(int,input().split())
	if t==0:
		ADD(a+1,b)
	else:
		print(SUM(b)-SUM(a))

Solution (Python):
n,q=map(int,input().split())
a=list(map(int,input().split()))
size=2*n+1
bit=[0]*size
def bit_update(x,v):
    while x<size:
        bit[x]+=v
        x+=(x&-x)
def bit_sum(n):
    s=0
    if n==0:return 0
    x=n
    while x>0:
        s+=bit[x]
        x-=(x&-x)
    return s
for i,j in enumerate(a,1):
    bit_update(i,j)
for i in range(q):
    a,b,c=map(int,input().split())
    if a==0:
        bit_update(b+1,c)
    else:
        print(bit_sum(c)-bit_sum(b))

Solution (Python):
class FenwickTree:
    def __init__(self, n, init_list=None):
        self.n = n
        self.data = [0] * n
        if init_list:
            assert n == len(init_list)
            for i in range(n):
                self.add(i, init_list[i])
        
    def add(self, i, val):
        assert 0 <= i < self.n
        i += 1
        while i <= self.n:
            self.data[i - 1] += val
            i += i & -i 
            
    def update(self, i, val):
        self.add(i, val - self.sum(i, i+1))

    def sum(self, l, r):
        assert  0 <= l <= r <= self.n
        if l != 0:
            return self.sum(0, r) - self.sum(0, l)
        ret = 0
        while r > 0:
            ret += self.data[r - 1]
            r -= r & -r 
        return ret

n, q = map(int, input().split())
a = list(map(int, input().split()))
ft = FenwickTree(n, a)
ans = []
for _ in range(q):
    i, l, r = map(int, input().split())
    if i == 0:
        ft.add(l, r)
    else:
        ans.append(ft.sum(l, r))

for x in ans:
    print(x)

Solution (Python):
class fenwick_tree():
    def __init__(self, n:int, mod:int = 0):
        self.__mod = mod
        self.__n = n
        self.__data = [0] * self.__n

    def add(self, p:int, x:int):
        assert (0 <= p) & (p < self.__n)
        if(self.__mod == 0):
            self.__add_mod0(p,x)
        else:
            self.__add_mod(p,x)

    def __add_mod0(self, p:int, x:int):
        p+=1
        while( p<= self.__n):
            self.__data[p-1] += x
            p += p & -p

    def __add_mod(self, p:int, x:int):
        p+=1
        while( p<= self.__n):
            self.__data[p-1] += x
            self.__data[p-1] %= self.__mod
            p += p & -p

    def sum(self, l:int, r:int):
        assert (0 <= l) & (l <= r) & (r <= self.__n)
        if(self.__mod == 0):
            return self.__sum_mod0(r) - self.__sum_mod0(l)
        else:
            return self.__sum_mod(r) - self.__sum_mod(l)

    def __sum_mod0(self, r:int):
        s = 0
        while(r > 0):
            s += self.__data[r-1]
            r -= r & -r
        return s

    def __sum_mod(self, r:int):
        s = 0
        while(r > 0):
            s += self.__data[r-1]
            s %= self.__mod
            r -= r & -r
        return s

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n,q = map(int,readline().split())
a = list(map(int,readline().split()))
query = list(map(int,read().split()))

ft = fenwick_tree(n)
ans = []

for i,ai in enumerate(a):
    ft.add(i,ai)

i = 0
for _ in range(q):
    if(query[i]==0):
        p,x = query[i+1:i+3]
        ft.add(p,x)
    else:
        l,r = query[i+1:i+3]
        ans.append(ft.sum(l,r))
    i += 3

print('\n'.join(map(str,ans)))

Solution (Python):
class fenwick_tree():
    def __init__(self, n:int):
        self.__n = n
        self.__data = [0] * self.__n

    def add(self, p:int, x:int):
        assert (0 <= p) & (p < self.__n)
        p+=1
        while( p<= self.__n):
            self.__data[p-1] += x
            p += p & -p

    def sum(self, l:int, r:int):
        assert (0 <= l) & (l <= r) & (r <= self.__n)
        return self.__sum_mod0(r) - self.__sum_mod0(l)

    def __sum_mod0(self, r:int):
        s = 0
        while(r > 0):
            s += self.__data[r-1]
            r -= r & -r
        return s


import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n,q = map(int,readline().split())
a = list(map(int,readline().split()))
query = list(map(int,read().split()))

ft = fenwick_tree(n)
ans = []

for i,ai in enumerate(a):
    ft.add(i,ai)

i = 0
for _ in range(q):
    if(query[i]==0):
        p,x = query[i+1:i+3]
        ft.add(p,x)
    else:
        l,r = query[i+1:i+3]
        ans.append(ft.sum(l,r))
    i += 3

print('\n'.join(map(str,ans)))

Solution (Python):
import sys


def sum(tree, i):
    s = 0
    while i > 0:
        s += tree[i]
        i -= i & -i
    return s


def add(tree, size,  i, x):
    while i <= size:
        tree[i] += x
        i += i & -i


def range_sum(tree, l, r):
    return sum(tree, r) - sum(tree, l)


def main():
    n, q = map(int, sys.stdin.buffer.readline().split())

    bit = [0] + list(map(int, sys.stdin.buffer.readline().split()))
    for i in range(1, n+1):
        if i + (i & -i) < n + 1:
            bit[i + (i & -i)] += bit[i]

    for y in sys.stdin.buffer.readlines():
        q, p, x = map(int, y.split())
        if q:
            print(range_sum(bit, p, x))
        else:
            add(bit,n, p+1, x)


if __name__ == "__main__":
    main()

Solution (Python):
import types

_atcoder_code = """


__version__ = '0.0.1'
"""

atcoder = types.ModuleType('atcoder')
exec(_atcoder_code, atcoder.__dict__)

_atcoder_fenwicktree_code = """
import typing


class FenwickTree:
    '''Reference: https://en.wikipedia.org/wiki/Fenwick_tree'''

    def __init__(self, n: int = 0) -> None:
        self._n = n
        self.data = [0] * n

    def add(self, p: int, x: typing.Any) -> None:
        assert 0 <= p < self._n

        p += 1
        while p <= self._n:
            self.data[p - 1] += x
            p += p & -p

    def sum(self, left: int, right: int) -> typing.Any:
        assert 0 <= left <= right <= self._n

        return self._sum(right) - self._sum(left)

    def _sum(self, r: int) -> typing.Any:
        s = 0
        while r > 0:
            s += self.data[r - 1]
            r -= r & -r

        return s
"""

atcoder.fenwicktree = types.ModuleType('atcoder.fenwicktree')
exec(_atcoder_fenwicktree_code, atcoder.fenwicktree.__dict__)
FenwickTree = atcoder.fenwicktree.FenwickTree






def main() -> None:
    import sys

    n, q = map(int, sys.stdin.readline().split())
    fenwick_tree = FenwickTree(n)

    a = map(int, sys.stdin.readline().split())
    for i, ai in enumerate(a):
        fenwick_tree.add(i, ai)

    for _ in range(q):
        t, x, y = map(int, sys.stdin.readline().split())
        if t == 0:
            fenwick_tree.add(x, y)
        if t == 1:
            print(fenwick_tree.sum(x, y))


if __name__ == '__main__':
    main()

Solution (Python):
N,Q=map(int,input().split())
alist=list(map(int,input().split()))


def BIT_query(idx):
  res_sum = 0
  while idx > 0:
    res_sum += BIT[idx]
    idx -= idx&(-idx)
  return res_sum

def BIT_update(idx,x):
  while idx <= N:
    BIT[idx] += x
    idx += idx&(-idx)
  return

BIT=[0]*(N+1)
for i in range(N):
  BIT_update(i+1,alist[i])

for _ in range(Q):
  q1,q2,q3=map(int,input().split())
  if q1==0:
    BIT_update(q2+1,q3)
  else:
    print(BIT_query(q3)-BIT_query(q2))

Solution (Python):
import sys
input = sys.stdin.readline
n, q = map(int,input().split())
A = list(map(int,input().split()))
C = [list(map(int,input().split())) for i in range(q)]


class Bit:  
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
  
    def sum(self, l, r):  
        
        s = 0
        while r > 0:
            s += self.tree[r]
            r -= r & -r
        while l > 0:
            s -= self.tree[l]
            l -= l & -l
        return s
  
    def add(self, i, x):  
        i += 1
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


def print_bit(B):
    n = B.size
    ANS = []
    for i in range(n):
        ANS.append(B.sum(i, i+1))
    print(*ANS)

B = Bit(n)
for i in range(n):
    B.add(i, A[i])

for i in range(q):
    if C[i][0] == 0:
        B.add(C[i][1], C[i][2])
    else:
        print(B.sum(C[i][1], C[i][2]))

Solution (Python):
class Bit:
    def __init__(self, n):
        """
        :param n: 最大の要素数
        """
        self.n = n
        self.tree = [0]*(n+1)
        self.depth = n.bit_length() - 1

    def sum(self, i):
        """ 区間[0,i) の総和を求める """
        s = 0
        i -= 1
        while i >= 0:
            s += self.tree[i]
            i = (i & (i + 1) )- 1
        return s

    def built(self, array):
        """ array を初期値とするBITを構築 """
        for i, a in enumerate(array):
            self.add(i, a)

    def add(self, i, x):
        """ i 番目の要素に x を足す """
        while i < self.n:
            self.tree[i] += x
            i |= i + 1

    def get(self, i, j):
        """ 部分区間和 [i, j) """
        if i == 0:
            return self.sum(j)
        return self.sum(j) - self.sum(i)

    def lower_bound(self, x, equal=False):
        """
        (a0+a1+...+ai < x となる最大の i (存在しない時は -1 ) , その時の a0+a1+...+ai )
        a0+a1+...+ai <= x としたい場合は equal = True
        二分探索であるため、ai>=0 を満たす必要がある
        """
        sum_ = 0
        pos = -1    
        if not equal:
            for i in range(self.depth, -1, -1):
                k = pos + (1 << i)
                if k < self.n and sum_ + self.tree[k] < x:  
                    sum_ += self.tree[k]
                    pos += 1 << i
        if equal:
            for i in range(self.depth, -1, -1):
                k = pos + (1 << i)
                if k < self.n and sum_ + self.tree[k] <= x: 
                    sum_ += self.tree[k]
                    pos += 1 << i
        return pos, sum_

    def __getitem__(self, i):
        """ [a0, a1, a2, ...] """
        return self.get(i, i+1)

    def __iter__(self):
        """ [a0, a1, a2, ...] """
        for i in range(self.n):
            yield self.get(i, i+1)

    def __str__(self):
        text1 = " ".join(["element:            "] + list(map(str, self)))
        text2 = " ".join(["cumsum(1-indexed):  "] + list(str(self.sum(i)) for i in range(1, self.n + 1)))
        return "\n".join((text1, text2))

n,q = map(int,input().split())
a = list(map(int,input().split()))
B = Bit(n)
B.built(a)

for _ in range(q):
    a,b,c = map(int,input().split())
    if a == 0:
        B.add(b, c)
    else:
        print(B.get(b, c))