Problem:

Range Minimum Query (RMQ)

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

find(s, t): report the minimum element in as, as+1, . . . ,at.

update(i, x): change ai to x.

Note that the initial values of ai (i = 0, 1, . . .  , n&minus;1) are  231-1.

Input

n q
com0 x0 y0
com1 x1 y1
...
comq&minus;1 xq&minus;1 yq&minus;1

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 update(xi, yi) and '1' denotes find(xi, yi).

Output

For each find operation, print the minimum element.

Constraints

1 ≤ n ≤ 100000

1 ≤ q ≤ 100000

If comi is 0, then 0 ≤ xi < n, 0 ≤ yi < 231-1.

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

Sample Input 1

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

Sample Output 1

1
2

Sample Input 2

1 3
1 0 0
0 0 5
1 0 0

Sample Output 2

2147483647
5



Sample input:
3 5
0 0 1
0 1 2
0 2 3
1 0 2
1 1 2


Sample output:
1
2

Submission status: Runtime Error

Solution code:
import sys
#stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

class SegmentTree:
    def __init__(self, func, arr, default):
        self.func = func
        self.arr = arr
        self.default = default
        
        self.arrlen = len(self.arr)
        self.bitlen = (len(self.arr)-1).bit_length() + 1
        self.bottomlen = pow(2, self.bitlen-1)
        self.bottomst = pow(2, self.bitlen-1) - 1
        
        self.segtree = [self.default] * (2*self.bottomlen - 1)
        self.segtree[self.bottomst:self.bottomst+self.arrlen] = self.arr
        
        for idx in range(self.bottomst-1, -1, -1):
            self.segtree[idx] = self.func(self.segtree[2*idx+1],
                                          self.segtree[2*idx+2])
    
    # idx番目の値をxに変更(0-indexed)
    def update(self, idx:int, x:int):
        idx += self.bottomst
        self.segtree[idx] = x
        while idx > 0:
            idx = (idx-1)//2
            self.segtree[idx] = self.func(self.segtree[2*idx+1],
                                          self.segtree[2*idx+2])
        
    # [a,b) の値を取得(0-indexed)
    def query(self, a:int, b:int, idx:int, l:int, r:int):
        if r <= a or b <= l:
            return self.default
        
        elif a <= l and r <= b:
            return self.segtree[idx]
        
        else:
            return self.func(self.query(a,b, 2*idx+1, l, (l+r)//2),
                             self.query(a,b, 2*idx+2, (l+r)//2, r))

    # リセット
    def reset(self):
        self.segtree = [self.default] * (2*self.bottomlen - 1)
        self.segtree[self.bottomst:self.bottomst+self.arrlen] = self.arr
        
        for idx in range(self.bottomst-1, -1, -1):
            self.segtree[idx] = self.func(self.segtree[2*idx+1],
                                          self.segtree[2*idx+2])
            

n,q = li()
default = pow(2,31)-1
arr = [default]*n
segtree = SegmentTree(min, arr, default)
nbit = pow(2, (n-1).bit_length())

for _ in range(q):
    command, a, b = li()
    
    if command == 0:
        segtree.update(a,b)
    
    elif command == 1:
        print(segtree.query(a,b+1,0,0,nbit))

Submission status: Runtime Error

Solution code:
import sys
import time
import math
sys.setrecursionlimit(20000)
def update(tree,x,y,N):
    # happa no offset
    x += N
    tree[x] = y
    # segment tree no update suru
    while x>0:
        x = int((x - 1)/2)
        left = x*2+1
        right = x*2+2
        if(right > N):
            right = right - 1
        tree[x] = min(tree[left],tree[right])

def find(tree,x,y,k,l,r):
    # mitu kara nakatta
    if ( r <= x or y <= l):
        return 2**31 - 1
    # sita wo mite itte mitukatta toki (intersect)
    if ( x <= l and r <= y):
        #print(k,l,r)
        return tree[k]
    # sita ni sagaru
    v_left = find(tree, x, y, k*2 + 1, l, int((l+r)/2))
    v_right = find(tree, x, y, k*2 + 2, int((l+r)/2), r)
    return min(v_left, v_right)

if __name__ == '__main__':
    _N,query_num = map(int, input().split())
    INT_MAX = 2**31 - 1
    N = _N*2
    A_bin_tree = [INT_MAX]*(N)
    #start = time.time()
    for i in range(query_num):
        operate,x,y = map(int, input().split())
        # update
        if(operate==0):
            update(A_bin_tree,x,y,_N)
            #print(A_bin_tree)
        # find
        if(operate==1):
            # tyouten kara miteiku
            x = find(A_bin_tree,x,y+1,0,0,N)
            print(x)
    #elapsed_time = time.time() - start
    #print ("elapsed_time:{0}".format(elapsed_time) + "[sec]")

Submission status: Runtime Error

Solution code:
import sys
import time
import math
sys.setrecursionlimit(20000)
def update(tree,x,y,N):
    # offset
    #x += int(N/2)
    x += N - 1
    tree[x] = y
    # segment tree no update suru
    while x>0:
        x = math.floor((x - 1)/2)
        left = x*2+1
        right = x*2+2
        tree[x] = min(tree[left],tree[right])

def find(tree,x,y,k,l,r):

    if (r <= x or y <= l):
        return 2**31 - 1
    # sita wo mite itte mitukatta toki (intersect)
    if ( x <= l and r <= y):
        return tree[k]
    # sita ni sagaru
    v_left = find(tree, x, y, k*2 + 1, l, int((l+r)/2))
    v_right = find(tree, x, y, k*2 + 2, int((l+r)/2), r)
    return min(v_left, v_right)

if __name__ == '__main__':
    _N,query_num = map(int, input().split())
    INT_MAX = 2**31 - 1
    N = 1
    while True:
        if(N >= _N):
            break
        N *= 2
    #N = 2*N - 1 - 1
    A_bin_tree = [INT_MAX]*(2*N - 1 - 1)
    #start = time.time()
    for i in range(query_num):
        operate,x,y = map(int, input().split())
        # update
        if(operate==0):
            update(A_bin_tree,x,y,N)
            #print(A_bin_tree)
        # find
        if(operate==1):
            # tyouten kara miteiku
            z = find(A_bin_tree,x,y+1,0,0,N)
            print(z)
    #elapsed_time = time.time() - start
    #print ("elapsed_time:{0}".format(elapsed_time) + "[sec]")

Submission status: Runtime Error

Solution code:
import math

INT_MAX = 2147483647
MAX = 100003
n,q=(int(x) for x in input().split())
b= math.sqrt(n)


def judge_max(x,y):
    
    if x > y :return x
    else:return y 

def judge_min(x,y):
    if x > y :return y
    else :return x



def update(x):
 
    for i in range(int(x*b),int(judge_min(n-1,(x+1)*b))):a[i]=l[int(x)]
    l[int(x)]=-1;
    return;
 

if __name__=='__main__':
    a = [INT_MAX for i in range(n)]
    l = [-1 for i in range(n)]
    
   
    for i in range(q):
        t, *com = (int(x) for x in input().split())
        if t : 
            x = com[0]
            if l[int(x/b)] != -1:update(x/b)
            print(a[x])
        else:
            x,y,z = com
            if l[int(x/b)] != -1:update(x/b)
            for i in range(x,int(judge_min(y,(x/b+1)*b))):a[i]=z
            for i in range(int(x/b)+1,int(y/b)):l[i]=z
            if l[int(y/b)] != -1:update(y/b)
            for i in range(int(judge_max(x,y/b**2)),y+1):a[i]=z

Submission status: Runtime Error

Solution code:
M = 2147483647
a = [M for i in range(100000)]

def j_min(x,y):
    if x < y:return x
    else: return y

def find(x,y,i,l,r):
    if r<=x or y<=l:return M
    if x<=l and r<=y: return a[i]
    return min(find(x,y,i*2,l,(l+r)/2),find(x,y,i*2+1,(l+r)/2,r))

if __name__=='__main__':
    n, m = (int(x) for x in input().split())
    t=1
    while t<n :t *= 2

    for i in range(m-1,-1,-1):
        com,x,y = (int(x) for x in input().split())
        if com :
            #continue
            print(find(x,y+1,1,0,t))
        else:
            x+=t
            a[x]=y
            while isinstance(x, int) or x >= 2:
               a[int(x/2)]=j_min(a[int(x)],a[int(x)^1])
               x/=2

Submission status: Runtime Error

Solution code:
M = 2147483647
a = [M for i in range(100000*2)]

def j_min(x,y):
    if x < y:return x
    else: return y

def find(x,y,i,l,r):
    if r<=x or y<=l:return M
    if x<=l and r<=y: return a[i]
    return min(find(x,y,i*2,l,(l+r)/2),find(x,y,i*2+1,(l+r)/2,r))

if __name__=='__main__':
    n, m = (int(x) for x in input().split())
    t=1
    while t<n :t *= 2

    for i in range(m-1,-1,-1):
        com,x,y = (int(x) for x in input().split())
        if com :
            #continue
            print(find(x,y+1,1,0,t))
        else:
            x+=t
            a[x]=y
            while isinstance(x, int) or x >= 2:
               a[int(x/2)]=j_min(a[int(x)],a[int(x)^1])
               x/=2

Submission status: Runtime Error

Solution code:
M = 2147483647
a = [M for i in range(100000*2)]

def j_min(x,y):
    if x < y:return x
    else: return y

def find(x,y,i,l,r):
    if r<=x or y<=l:return M
    if x<=l and r<=y: return a[i]
    return j_min(find(x,y,i*2,l,(l+r)/2),find(x,y,i*2+1,(l+r)/2,r))

if __name__=='__main__':
    n, m = (int(x) for x in input().split())
    t=1
    while t<n :t *= 2

    for i in range(m-1,-1,-1):
        com,x,y = (int(x) for x in input().split())
        if com :
            #continue
            print(find(x,y+1,1,0,t))
        else:
            x+=t
            a[x]=y
            while isinstance(x, int) or x >= 2:
               a[int(x/2)]=j_min(a[int(x)],a[int(x)^1])
               x/=2

Submission status: Runtime Error

Solution code:
import math
class segment_tree:
    
    # self.table is 1-indexed
    def __init__(self, dat, query, default=0):
        self.offset = 2 ** math.ceil(math.log2(len(dat)))
        self.table = [default] * self.offset + dat + [default] * (self.offset - len(dat))
        self.query = query
        for i in reversed(range(1, self.offset)):
            self.table[i] = self.query(self.table[2 * i], self.table[2 * i + 1])

    # [l, r] closed-interval
    def find(self, l, r):
        return self.query(self.__range(l,r))

    def __range(self, l, r):
        l += self.offset
        r += self.offset
        while l <= r:
            if l & 1:
                yield self.table[l]
                l += 1
            l >>= 1
            if r & 1 == 0:
                yield self.table[r]
                r -= 1
            r >>= 1
        
    def update(self, i, x):
        i += self.offset
        self.table[i] = x
        while 1 < i:
            i >>= 1
            self.table[i] = self.query(self.table[2 * i], self.table[2 * i + 1])

import sys
f = sys.stdin


n, q = map(int, f.readline().split())

rmq = segment_tree([(1 << 31) - 1] * n, min, float('inf'))

function = (rmq.update, lambda x, y:print(rmq.find(x, y)))
for com, x, y in (map(int, f.readline().split()) for _ in range(q)):
    function[com](x, y)

Submission status: Runtime Error

Solution code:
n,q = map(int,raw_input().split())
A = [2**31-1 for i in range(n)]
B = [2**31-1]*317
for i in range(q):
    comi,xi,yi = map(int,raw_input().split())
    if comi and yi<316:
        print min(A[xi:yi+1])
    elif comi and yi >= 316 and xi/316+1 != yi/316:
        print min(min(A[xi:(xi/316 + 1)*316]),min(B[xi/316+1:yi/316]),min(A[(yi/316)*316:yi+1]))
    elif comi and yi >= 316 and xi/316+1 == yi/316:
        print min(min(A[xi:(xi/316 + 1)*316]),min(A[(yi/316)*316:yi+1]))
    else:
        A[xi]=yi
        B[xi/316] = min(B[xi/316],yi)

Submission status: Runtime Error

Solution code:
n,q = map(int,raw_input().split())
A = [2**31-1 for i in range(n)]
B = [2**31-1 for i in range(318)]
for i in range(q):
    comi,xi,yi = map(int,raw_input().split())
    if comi and yi<316:
        print min(A[xi:yi+1])
    elif comi and yi >= 316 and xi/316+1 != yi/316:
        print min(min(A[xi:(xi/316 + 1)*316]),min(B[xi/316+1:yi/316]),min(A[(yi/316)*316:yi+1]))
    elif comi and yi >= 316 and (xi/316+1) == yi/316:
        print min(min(A[xi:(xi/316 + 1)*316]),min(A[(yi/316)*316:yi+1]))
    else:
        A[xi]=yi
        B[xi/316] = min(B[xi/316],yi)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
# Range Minimum Query

n,q = map(int,raw_input().split())
A = [2**31-1 for i in range(n)]
B = [2**31-1]*101
for i in range(q):
    comi,xi,yi = map(int,raw_input().split())
    if comi and abs(yi-xi)<=199:
        print min(A[xi:yi+1])
    elif comi and 200<= abs(yi-xi):
        print min(min(A[xi:(xi/100+1)*100]),min(B[xi/100+1:yi/100]),min(A[yi/100:]))
    else:#comi == 0
        A[xi]=yi
        B[xi/100] = min(B[xi/100],yi)

Submission status: Runtime Error

Solution code:
class RangeMinQuery:
    inf = 2 ** 31 - 1
    def __init__(self, N):
        self.n = 1
        while self.n < N: self.n *= 2
        self.dat = [self.inf] (2 * self.n - 1)

    def update(self, k, x):
        k += self.n - 1
        self.dat[k] = x
        while (k > 0):
            k = (k - 1) / 2
            self.dat[k] = min(self.dat[2 * k + 1], self.dat[2 * k + 2])

    # [a, b); call query(a, b)
    def query(self, a, b, k = 0, l = 0, r = -1):
        if r == -1: r = self.n
        if r <= a  or b <= l: return self.inf
        if a <= l and r <= b: return self.dat[k]

        vl = self.query(a, b, 2 * k + 1, l, (l + r) / 2)
        vr = self.query(a, b, 2 * k + 2, (l + r) / 2, r)
        return min(vl, vr)

n, q = map(int, raw_input().split())
rmq = RangeMinQuery(n)
for i in xrange(q):
    c, x, y = map(int, raw_input().split())
    if c == 0:
        c.update(x, y)
    else:
        print c.query(x, y + 1)

Submission status: Runtime Error

Solution code:
#!/usr/bin/python3
import math

# main
n, q = map(int, input().split())
b_size = math.ceil(math.sqrt(n))
b_len = math.ceil(n/b_size)
a = [2 ** 31 - 1 for i in range(n)]
b = [min(a[b_size * i:b_size * (i + 1)]) for i in range(b_len)]
for i in range(q):
    com, x, y = map(int, input().split())
    if com == 0:
        # update
        a[x] = y
        # update b
        index = x // b_size
        if b[index] > y:
            b[index] = y
    else:
        # find
        target = []
        x_index = x // b_size
        y_index = y // b_size
        x_mod = x % b_size
        y_mod = y % b_size
        if x_index == y_index:
            target.extend(a[x:y])
        else:
            if x_mod == 0:
                target.append(b[x_index])
            else:
                target.extend(a[x:x + (4 - 1)])

            if y_mod == 3:
                target.append(b[y_index])
            else:
                target.extend(a[y_index * b_size:y])

            if x_index + 1 <= y_index - 1:
                target.append(min(b[x_index + 1 : y_index - 1]))
        print(min(target))

Submission status: Runtime Error

Solution code:
#!/usr/bin/python3
import math

# main
n, q = map(int, input().split())
b_size = math.ceil(math.sqrt(n))
b_len = math.ceil(n/b_size)
a = [2 ** 31 - 1 for i in range(n)]
b = [min(a[b_size * i:b_size * (i + 1)]) for i in range(b_len)]
for i in range(q):
    com, x, y = map(int, input().split())
    if com == 0:
        # update
        a[x] = y
        # update b
        index = x // b_size
        if b[index] > y:
            b[index] = y
    else:
        # find
        target = []
        x_index = x // b_size
        y_index = y // b_size
        x_mod = x % b_size
        y_mod = y % b_size
        if x_index == y_index:
            target.extend(a[x:y + 1])
        else:
            if x_mod == 0:
                target.append(b[x_index])
            else:
                target.extend(a[x:(x_index + 1) * b_size])

            if y_mod == 3:
                target.append(b[y_index])
            else:
                target.extend(a[y_index * b_size:y + 1])

            if x_index + 1 <= y_index - 1:
                target.append(min(b[x_index + 1 : y_index - 1]))
        print(min(target))

Submission status: Runtime Error

Solution code:
l = raw_input().split()
#l=input[0].split()

n = int(l[0])
a = [2147483647]*50000
change = 1

for i in range(0,int(l[1])):
	l = raw_input().split()
#	l=input[i+1].split()
	if int(l[0])==0:
		a[int(l[1])]=int(l[2])
		change = 1
	elif change==l[1]+l[2]:
		print m
	else:
		change = l[1]+l[2]
		m = min(a[int(l[1]):int(l[2])+1])
		print m

Submission status: Runtime Error

Solution code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin
 
 
def main(init=int(2**31-1), readline=stdin.readline):
    n, q = (int(s) for s in readline().split())
 
    a = [init] * n
    b = [init] * ((n // 100) + 1)
 
    for _ in range(q):
        com, x, y = (int(s) for s in readline().split())
        if com:
            bx = x - (x % 100) + 100
            by = y - (y % 100)
            if bx < by:
                m = min(min(a[x:bx]), min(b[bx//100:by//100]),
                        min(a[by:y+1]))
            else:
                m = min(a[x:y+1])
            print(m)
        else:
            a[x] = y
            bx = x - (x % 100)
            b[x//100] = min(a[bx:bx+100])
 
 
main()

Submission status: Runtime Error

Solution code:
import math
num,query = (int(n) for n in input().split(' '))
table = [2**31 - 1 for n in range(num)]
sqrttable = []
sqrtnum = math.floor(math.sqrt(num))
tempmin = float("inf")
for t in range(num):
    if t % sqrtnum == sqrtnum - 1:
        tempmin = min(table[t],tempmin)
        sqrttable.append(tempmin)
    elif t == num - 1:
        tempmin = min(table[t],tempmin)
        sqrttable.append(tempmin)
    else:
        tempmin = min(table[t],tempmin)

for q in range(query):
    #print(sqrtnum,table,sqrttable)
    temp = [int(n) for n in f.readline().split(' ')]
    if temp[0] == 0:
        table[temp[1]] = temp[2]
        tempmin = float("inf")
        for tm in range(sqrtnum*(temp[1]//sqrtnum),min(num,sqrtnum*(temp[1]//sqrtnum + 1))):
            tempmin = min(table[tm],tempmin)
        sqrttable[temp[1]//sqrtnum] = tempmin
    else:
        tempmin = float("inf")
        if temp[1] % sqrtnum != 0:
            for ini in range(temp[1],min(temp[2]+1,sqrtnum * math.ceil(temp[1] / sqrtnum))):
                tempmin = min(tempmin,table[ini])
        newtemp2 = temp[2] + 1
        for sqt in range(math.ceil(temp[1] / sqrtnum),newtemp2 // sqrtnum):
            tempmin = min(sqrttable[sqt],tempmin)
        if temp[2] % sqrtnum != sqrtnum -1:
            for end in range(max(temp[1],sqrtnum * (temp[2]//sqrtnum)),temp[2]+1):
                tempmin = min(tempmin,table[end])
        #print(tempmin,sqrtnum,temp[1],temp[2],table,sqrttable)
        print(tempmin)

Submission status: Runtime Error

Solution code:
import math

def update(index,n):
    targ[index] = n
    index = (index - 1) // 2
    while True:
        targ[index] = min(targ[index * 2],targ[index * 2 + 1])
        if index <= 0:
            break
        index = (index - 1) // 2

def find(i,e,node,inode,enode):
    #print(i,e,node,inode,enode)
    if inode > e or enode < i:
        return float("inf")
    elif (i <= inode and enode <= e) or inode==enode:
        return targ[node]

    else:
        irange = find(i,e,2*node + 1,inode,(inode+enode)// 2 )
        erange = find(i,e,2*node + 2,(inode+enode)//2 + 1,enode)
        return min(irange,erange)

num,query = (int(n) for n in input().split(' '))
initial = 2147483647
ln = 2 ** math.ceil(math.log2(num)) - 1
global targ
targ = [initial] * (ln + num)
length = num - 1

for q in range(query):
    #print(targ)
    temp = [int(n) for n in input().split(' ') ]
    if temp[0] == 0:
        update(temp[1] + ln,temp[2])
    else:
        print(find(temp[1],temp[2],0,0,length))

Submission status: Runtime Error

Solution code:
import pdb; 

dat = []

def init(n):
  global dat
  k = 1
  while (k < n):
    k = k * 2
  dat = [2**31 - 1 for i in range(2 * k - 1)]

def update(k, y):
  global dat
  k += n
  dat[k] = y;
  while (k > 0):
    k = int((k - 1) / 2)
    dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2])
    
def query(a, b, k, l, r):
  if (r <= a or b <= l):
    return 2**31 - 1
  if (a <= l and r <= b):
    return dat[k]
  
  vl = query(a, b, k * 2 + 1, l, int((l + r) / 2))
  vr = query(a, b, k * 2 + 2, int((l + r / 2)), r)

  return min(vl, vr)

# main
n, q = map(int, input().split())

init(n)

for i in range(q):
  com, x, y = map(int, input().split())
  if com == 0:
    update(x, y)
  else:
    
    print(query(x, y+1, 0, 0, len(dat)))

Submission status: Runtime Error

Solution code:

dat = []

def init(n):
  global dat
  k = 1
  while (k < n):
    k = k * 2
  dat = [2**31 - 1 for i in range(2 * k - 1)]

def update(k, y):
  global dat
  k += n
  dat[k] = y;
  while (k > 0):
    k = int((k - 1) / 2)
    dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2])
    
def query(a, b, k, l, r):
  if (r <= a or b <= l):
    return 2**31 - 1
  if (a <= l and r <= b):
    return dat[k]
  
  vl = query(a, b, k * 2 + 1, l, int((l + r) / 2))
  vr = query(a, b, k * 2 + 2, int((l + r / 2)), r)

  return min(vl, vr)

# main
n, q = map(int, input().split())

init(n)

for i in range(q):
  com, x, y = map(int, input().split())
  if com == 0:
    update(x, y)
  else:
    
    print(query(x, y+1, 0, 0, len(dat)))

Submission status: Runtime Error

Solution code:
dat = []

def init(n):
  global dat
  k = 1
  while (k < n):
    k = k * 2
  dat = [2**31 - 1 for i in range(2 * k - 1)]

def update(k, y):
  global dat
  k += len(dat) - 1
  dat[k] = y;
  while (k > 0):
    k = int((k - 1) / 2)
    dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2])

def query(a, b, k, l, r):
  if (r <= a or b <= l):
    return 2**31 - 1
  if (a <= l and r <= b):
    return dat[k]
  
  vl = query(a, b, k * 2 + 1, l, int((l + r) / 2))
  vr = query(a, b, k * 2 + 2, int((l + r / 2)), r)

  return min(vl, vr)

# main
n, q = map(int, input().split())

init(n)

for i in range(q):
  com, x, y = map(int, input().split())
  if com == 0:
    update(x, y)
  else:
    
    print(query(x, y+1, 0, 0, len(dat)))

Submission status: Runtime Error

Solution code:
def updt(lst, i, x):
    lst[i] = x


def fnd(lst, s, t):
    return min(lst[s:t])


def rmq():
    n, q = map(int, input().split())
    A = [x for x in range(n)]
    ans = []
    for _ in range(q):
        cmd, x, y = map(int, input().split())
        if cmd == 0:
            updt(A, x, y)
        else:
            ans.append(fnd(A, x, y))
    print(*ans, sep="\n")


if __name__ == "__main__":
    rmq()

Submission status: Runtime Error

Solution code:
import sys


def updt(lstv, lstk, i, x):
    lstv[i] = x
    lstk[i] = i


def fnd(lstv, lstk, s, t):
        if max(lstk[s:t+1]) == -1:
            return 2**31 -1
        else:
            m = 2**31 -1
            for k in lstk[s:t+1]:
                if k >= 0:
                    if m > lstv[k]:
                        m = lstv[k]
            return m

def rmq():
    n, q = map(int, sys.stdin.reakline().split())
    Av = [0 for _ in range(n)]
    Ak = [-1 for _ in range(n)]
    ans = []
    for _ in range(q):
        cmd, x, y = map(int, sys.stdin.reakline().split())
        if cmd == 0:
            updt(Av, Ak, x, y)
        else:
            ans.append(fnd(Av, Ak, x, y))
    print(*ans, sep="\n")


if __name__ == "__main__":
    rmq()

Submission status: Runtime Error

Solution code:
import numpy as np
n,q = map(int, input().split())
A = np.array([float("inf")] * n)
for i in range(q):
 c,x,y = map(int,input().split())
 if c == 0:
  A[x] = y
 else:
  a = np.min(A[x:y+1])
  if a == float("inf"): a = "2147483647"
  else: a = str(a)
  print(a)

Submission status: Runtime Error

Solution code:
import numpy as np
n,q = map(int, input().split())
A = np.array([None] * n)
for i in range(q):
 c,x,y = map(int,input().split())
 if c == 0:
  A[x] = y
 else:
  a = np.min(A[x:y+1])
  if a is None: a = "2147483647"
  else: a = str(a)
  print(a)

Submission status: Runtime Error

Solution code:
n,q = map(int, input().split())
A = [None] * n
for i in range(q):
 c,x,y = map(int,input().split())
 if c == 0:
  A[x] = y
 else:
  a = min(A[x:y+1])
  if a is None: a = "2147483647"
  else: a = str(a)
  print(a)

Submission status: Runtime Error

Solution code:
class RMQ:
    import math

    def __init__(self, length):
        self.length = 2 ** math.ceil(math.log(length, 2))
        self.segtree = [float("inf")] * (2 ** (self.length + 1) - 1)

    def update(self, index, n):
        leaf_index = index + self.length - 1
        self.segtree[leaf_index] = n
        while leaf_index > 0:
            leaf_index = (leaf_index - 1) // 2
            self.segtree[leaf_index] = min(self.segtree[leaf_index * 2 + 1], self.segtree[leaf_index * 2 + 2])

    def find(self, a, b, index, l, r):
        if b < l or r < a:
            return float("inf")
        elif a <= l <= r <= b:
            return self.segtree[index]
        else:
            return min(self.find(a, b, index * 2 + 1, l, (l + r) // 2), self.find(a, b, index * 2 + 2, (l + r) // 2, r))

v_num, query = (int(n) for n in input().split(" "))
rmq = RMQ(v_num)
for _ in range(query):
    com, i, n = (int(n) for n in input().split(" ") )
    if com == 0:
        rmq.update(i, n)
    else:
        print(rmq.find(i, n, 0, 0, rmq.length))

Submission status: Runtime Error

Solution code:
class RMQ:
    def __init__(self, length, ini_num = float("inf")):
        self.length = 1
        while self.length <= n:
            self.length <<= 1
        self.segtree = [ini_num] * (2 * self.length - 1)

    def update(self, index, n):
        leaf_index = index + self.length - 1
        self.segtree[leaf_index] = n
        while leaf_index > 0:
            leaf_index = (leaf_index - 1) // 2
            self.segtree[leaf_index] = min(self.segtree[leaf_index * 2 + 1], self.segtree[leaf_index * 2 + 2])

    def find(self, a, b, index, l, r):
        if a <= l <= r <= b or a == b:
            return self.segtree[index]
        if b <= l or r <= a:
            return float("inf")
        else:
            return min(self.find(a, b, index * 2 + 1, l, (l + r) // 2), self.find(a, b, index * 2 + 2, (l + r) // 2, r))

v_num, query = (int(n) for n in input().split(" "))
rmq = RMQ(v_num, 2147483647)
for _ in range(query):
    com, i, n = (int(n) for n in input().split(" ") )
    if com == 0:
        rmq.update(i, n)
    else:
        (rmq.find(i, n, 0, 0, rmq.length))

Submission status: Runtime Error

Solution code:
class RMQ:
    def __init__(self, length, ini_num = float("inf")):
        self.length = 1
        while self.length <= n:
            self.length <<= 1
        self.segtree = [ini_num] * (2 * self.length - 1)

    def update(self, index, n):
        leaf_index = index + self.length - 1
        self.segtree[leaf_index] = n
        while leaf_index > 0:
            leaf_index = (leaf_index - 1) // 2
            self.segtree[leaf_index] = min(self.segtree[leaf_index * 2 + 1], self.segtree[leaf_index * 2 + 2])

    def find(self, a, b, index, l, r):
        if a <= l <= r <= b or a == b:
            return self.segtree[index]
        if b <= l or r <= a:
            return float("inf")
        else:
            return min(self.find(a, b, index * 2 + 1, l, (l + r) // 2), self.find(a, b, index * 2 + 2, (l + r) // 2, r))

v_num, query = (int(n) for n in input().split(" "))
rmq = RMQ(v_num, 2147483647)
for _ in range(query):
    com, i, n = (int(n) for n in input().split(" ") )
    if com == 0:
        rmq.update(i, n)
    else:
        print(rmq.find(i, n, 0, 0, rmq.length))

Submission status: Runtime Error

Solution code:
class SegmentTree():
	def __init__(self,n):
		self.dat = [INF for _ in range(n*2-1)]
		#index n???????????????????????¢?????????:
		#???????????? : (n-1)//2
		#???????????? : (2n+1) , (2n+2)
		self.n = n

	def update (self,node_index,value):
		""" index?????????value????????´?????? """
		index = node_index + (self.n-1) #node_index????????????dot???index?????????
		self.dat[index] = value

		#?????°????????????????????????????????´????????????
		while index > 0 :
			index = (index - 1) // 2				 #???????????????????????£???
			self.dat[index] = min([self.dat[index*2+1],self.dat[index*2+2]]) #??????????????????????????????

	def querry (self,left,right,nowNode,nowLeft,nowRight):
		"""[left,right):??¢?´¢??????,noeNode:?????¨????????????,[nowLeft,nowRight):?????¨?????????????????????"""

		# ??????????????¶??£????????????
		if nowRight < left or nowLeft > right:
			return INF

		# ?????¨?????¢?´¢???????????¨????????????????????????????????????
		if left <= nowLeft and nowRight <= right:
			return self.dat[nowNode]

		# ???????????????????????????????????¨???????????????
		else:
			value_left =self.querry(left,right,2*nowNode+1,nowLeft,(nowLeft+nowRight)//2)
			value_right = self.querry(left,right,2*nowNode+2,(nowLeft+nowRight)//2+1,nowRight)
			return min([value_left,value_right])

	def DEBUG_dat(self):
		print(self.dat)
		

if __name__ == "__main__":
	# ??????????????????
	INF = 2147483647
	n ,q  = map(int,input().split(" "))
	result = []

	for i in range(1,9):
		if 2 ** i >= n:
			min_pow2 = 2 **  i
			break

	tree = SegmentTree(min_pow2)

	for i in range(q):
		com,x,y = map(int,input().split(" "))
		if com == 0:
			tree.update(x,y)
		else:
			result.append(tree.querry(x,y,0,0,min_pow2-1))

	for i in result:
		print(i)

Submission status: Runtime Error

Solution code:
import numpy as np

def update(a, i, x) :
    a[i] = x


def find(a, s, t) :
    return a[s:t+1].min()


def main() :
    n, q = [int(i) for i in input().split()]
    a = np.ones(n, dtype=int) * (2**31 - 1)
    com = np.array([], dtype=int)
    x = np.array([], dtype=int)
    y= np.array([], dtype=int)
    for _ in range(q) :
        tmp = list(map(int, input().split()))
        com = np.append(com, tmp[0])
        x = np.append(x, tmp[1])
        y = np.append(y, tmp[2])

    for i in range(q) :
        if com[i] == 0 :
            update(a, x[i], y[i])
        elif com[i] == 1 :
            print(find(a, x[i], y[i]))


if __name__ == '__main__' :
    main()

Submission status: Runtime Error

Solution code:
import numpy

def update(a, i, x) :
    a[i] = x


def find(a, s, t) :
    return a[s:t+1].min()


def main() :
    n, q = [int(i) for i in input().split()]
    a = numpy.ones(n, dtype=int) * (2**31 - 1)
    com = numpy.array([], dtype=int)
    x = numpy.array([], dtype=int)
    y= numpy.array([], dtype=int)
    for _ in range(q) :
        tmp = list(map(int, input().split()))
        com = numpy.append(com, tmp[0])
        x = numpy.append(x, tmp[1])
        y = numpy.append(y, tmp[2])

    for i in range(q) :
        if com[i] == 0 :
            update(a, x[i], y[i])
        elif com[i] == 1 :
            print(find(a, x[i], y[i]))


if __name__ == '__main__' :
    main()