Problem p02559 (python)

Fixed submission:
class BIT:
            
    def __init__(self, L):
        self.N = len(L)
        self.bit = [0]*self.N
        for i,l in enumerate(L):
            self.add(i,l)
        self.N0 = 1
        while self.N0*2 <= self.N:
            self.N0 *= 2

    def add(self, a, w):
        x = a + 1
        for i in range(1000):
            self.bit[x-1] += w
            x += x & -x
            if x > self.N:
                break

    def sum(self, a):
        x = a+1
        ret = 0
        for i in range(1000):
            ret += self.bit[x-1]
            x -= x & -x
            if x <= 0:
                break        
        return ret

    #you can use this function when the BIT has only non-negative values.
    def lower_bound(self, w):
        if w<=0:
            return 0
        x = 0
        k = self.N0
        while k>0:
            if x+k<=self.N:
                if self.bit[x+k-1]<w:
                    w-=self.bit[x+k-1]
                    x+=k
            k//=2
        return x


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

for i in range(Q):
    f,a,b = list(map(int,input().split()))
    if f==0:
        bit.add(a, b)
    else:
        if a==0:
            print(bit.sum(b-1))
        else:
            print(bit.sum(b-1)-bit.sum(a-1))

Buggy submission (verdict: Runtime Error):
# distutils: language=c++
# distutils: include_dirs=[/home/contestant/.local/lib/python3.8/site-packages/numpy/core/include, /opt/atcoder-stl]
# cython: boundscheck=False
# cython: wraparound=False
cimport numpy as np
cdef extern from "<atcoder/fenwicktree>" namespace "atcoder" nogil:
    cdef cppclass fenwick_tree[T]:
        fenwick_tree(int n)
        void add(int p, T x)
        T sum(int l, int r)

cdef class FenwickTree:
    cdef fenwick_tree[long long] *_thisptr
    def __cinit__(self, np.ndarray[long, ndim=1] array):
        cdef int N = array.size
        self._thisptr = new fenwick_tree[long long](N)
        for i in range(N):
            self.add(i, array[i])
    cpdef void add(self, int p, long long x):
        self._thisptr.add(p, x)
    cpdef long long sum(self, int l, int r):
        return self._thisptr.sum(l, r)

Buggy submission (verdict: Runtime Error):

code = """

# distutils: language=c++
# distutils: include_dirs=[/home/USERNAME/.local/lib/python3.8/site-packages/numpy/core/include, /opt/atcoder-stl]
# cython: boundscheck=False
# cython: wraparound=False


cimport numpy as np
cdef extern from "<atcoder/fenwicktree>" namespace "atcoder" nogil:
    cdef cppclass fenwick_tree[T]:
        fenwick_tree(int n)
        void add(int p, T x)
        T sum(int l, int r)

ctypedef np.int DTYPE_t

cdef class FenwickTree:
    cdef fenwick_tree[long long] *_thisptr
    def __cinit__(self, np.ndarray[DTYPE_t, ndim=1] array):
        cdef int N = array.size()
        self._thisptr = new fenwick_tree[long long](N)
        for i in range(N):
            self.add(i, array[i])
    cpdef void add(self, int p, long long x):
        self._thisptr.add(p, x)
    cpdef long long sum(self, int l, int r):
        return self._thisptr.sum(l, r)
"""


import os, sys, getpass

if sys.argv[-1] == 'ONLINE_JUDGE':
    code = code.replace("USERNAME", getpass.getuser())
    open('atcoder.pyx','w').write(code)
    os.system('cythonize -i -3 -b atcoder.pyx')
    sys.exit(0)


from atcoder import FenwickTree
import numpy as np

N,Q = list(map(int,input().split()))
bit = FenwickTree(np.array(list(map(int,input().split())), dtype=np.int))

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

Buggy submission (verdict: Runtime Error):

code = """

# distutils: language=c++
# distutils: include_dirs=[/home/contestant/.local/lib/python3.8/site-packages/numpy/core/include, /opt/atcoder-stl]
# cython: boundscheck=False
# cython: wraparound=False


cdef extern from "<atcoder/fenwicktree>" namespace "atcoder":
    cdef cppclass fenwick_tree[T]:
        fenwick_tree(int n)
        void add(int p, T x)
        T sum(int l, int r)

cdef class FenwickTree:
    cdef fenwick_tree[long long] *_thisptr
    def __cinit__(self, int n):
        self._thisptr = new fenwick_tree[long long](n)
    cpdef void add(self, int p, long long x):
        self._thisptr.add(p, x)
    cpdef long long sum(self, int l, int r):
        return self._thisptr.sum(l, r)
"""


import os,sys
if sys.argv[-1] == 'ONLINE_JUDGE':
    open('atcoder.pyx','w').write(code)
    os.system('cythonize -i -3 -b atcoder.pyx')


from atcoder import FenwickTree

readline = sys.stdin.buffer.readline

N, Q = list(map(int, readline().split()))
ft = FenwickTree(N)

A = list(map(int, readline().split()))

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

for i in range(N):
    a, b, c = list(map(int, readline().split()))
    if a == 0:
        ft.add(b, c)
    else:
        print(ft.sum(b, c))