Problem:
Range Minimum Query (RMQ) Write a program which manipulates a sequence A = { a 0 , a 1 , . . .  , a n-1 } with the following operations:  find(s, t) : report the minimum element in a s , a s+1 , . . . ,a t .  update(i, x) : change a i to x .  Note that the initial values of a i ( i = 0, 1, . . .  , n−1 ) are  2 31 -1. Input  n  q  com 0  x 0  y 0  com 1  x 1  y 1 ... com q−1  x q−1  y q−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(x i , y i ) and '1' denotes find(x i , y i ) . Output For each find operation, print the minimum element. Constraints   1 ≤ n ≤ 100000    1 ≤ q ≤ 100000   If com i is 0, then 0 ≤ x i < n , 0 ≤ y i < 2 31 -1 .  If com i is 1, then 0 ≤ x i < n , 0 ≤ y i < 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

Solution (Python):
import sys
input = sys.stdin.readline

class SegmentTree:
    
    def __init__(self, list_, ide_ele=0):
        tmp = 1
        while tmp < len(list_):
            tmp *= 2
        self.n = tmp
        self.l = [ide_ele] * (2 * self.n - 1)
        self.ide_ele = ide_ele
        self.init_val(list_)

    def func(self, x, y):
        return min(x, y)

    def init_val(self, list_):
        
        for i, val in enumerate(list_):
            self.l[self.n - 1 + i] = val
        
        for i in range(self.n-2, -1, -1):
            self.l[i] = self.func(self.l[i*2+1], self.l[i*2+2])
    
    
    def update(self, i, val):
        i = self.n - 1 + i
        self.l[i] = val
        while i > 0:
            i = (i-1) // 2
            self.l[i] = self.func(self.l[i*2+1], self.l[i*2+2])
    
    
    def query(self, a, b, k, l, r):
        if r <= a or b <= l:
            return self.ide_ele  
        if a <= l and r <= b:
            return self.l[k]
        vl = self.query(a, b, k*2+1, l, (l+r)//2)
        vr = self.query(a, b, k*2+2, (l+r)//2, r)
        return self.func(vl, vr)

def main():
    N, Q = map(int, input().split())
    tmp = (1 << 31) - 1
    seg = SegmentTree([tmp] * N, ide_ele=tmp)

    
    

    for i in range(Q):
        c, x, y = map(int, input().split())
        if c == 0:
            
            seg.update(x, y)
        else:
            
            print(seg.query(x, y+1, 0, 0, seg.n))
        

if __name__ == "__main__":
    main()

Solution (Python):
INT_MAX = 2**31-1
MAX_N = 10**5

def init(n_):
    n = 1
    while n < n_:
        n *= 2
    dat = [INT_MAX] * (2*n-1)
    return n, dat

def update(k, a):
    k += n-1
    dat[k] = a
    while k > 0:
        k = (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 INT_MAX
    if a <= l and r <= b:
        return dat[k]
    else:
        vl = query(a, b, k*2+1, l, (l+r)//2)
        vr = query(a, b, k*2+2, (l+r)//2, r)
        return min(vl, vr)

if __name__ == "__main__":
    n, q = map(int, input().split())
    n, dat = init(n)
    for i in range(q):
        com, x, y = map(int, input().split())
        if com == 0:
            update(x, y)
        elif com == 1:
            print(query(x, y+1, 0, 0, n))

Solution (Python):
class SqrtDecomposition():
    def __init__(self, array, f):
        self.dat = array
        self.f = f
        m = int(pow(len(array), 0.5))
        if m**2 < len(array):
            m += 1
        self.m = m
        self.dat2 = []
        for i in range(m):
            if i * m >= len(array):
                break
            self.dat2 += [f(self.dat[m * i:m * (i + 1)])]

    def update(self, a, x):
        m = self.m
        dat = self.dat
        dat2 = self.dat2
        f = self.f
        dat[a] = x
        a2 = a // m
        al = m * a2
        ar = al + m
        dat2[a2] = f(dat[al:ar])

    def query(self, a, b):
        dat = self.dat
        dat2 = self.dat2
        f = self.f
        m = self.m
        a2 = a // m
        ar = a2 * m + m
        b2 = b // m
        bl = b2 * m
        if ar > bl:
            return f(dat[a:b])
        else:
            return f(dat[a:ar] + dat2[a2 + 1:b2] + dat[bl:b])


N, Q = [int(_) for _ in input().split()]
Query = [[int(_) for _ in input().split()] for _ in range(Q)]
SD = SqrtDecomposition(array=[2**31 - 1] * N, f=min)
for query in Query:
    if query[0]:
        query[2] += 1
        print(SD.query(*query[1:]))
    else:
        SD.update(*query[1:])

Solution (Python):
class SegTree:
    def __init__(self,N,f,ini):
        """
        f(val,ini)=ini
        """
        n=1
        while n<N: n<<=1
        self.n=n
        self.arr=[ini]*(2*n-1)
        self.f,self.ini=f,ini
    
    def update(self,i,val):
        i += self.n-1
        self.arr[i]=val
        while i>0:
            i=(i-1)//2
            self.arr[i]=self.f(self.arr[2*i+1],self.arr[2*i+2])

    def find(self,s,t):
        """
        [s,t)
        """
        return self.__find(s,t,0,0,self.n)

    def __find(self,s,t,k,l,r):
        if t<=l or s>=r: return self.ini
        if s<=l and t>=r: return self.arr[k]
        vl=self.__find(s,t,2*k+1,l,(l+r)//2)
        vr=self.__find(s,t,2*k+2,(l+r)//2,r)
        return self.f(vl,vr)

N,Q=map(int,input().split())
CXY=[map(int,input().split()) for _ in range(Q)]
st = SegTree(N, lambda x,y: min(x,y), 2**31-1)

for c,x,y in CXY:
    if c==0:
        
        st.update(x,y)
    elif c==1:
        
        print(st.find(x,y+1))

Solution (Python):
import sys
def input():
	return sys.stdin.readline()[:-1]

INF = (1<<31)-1

class Rmin():
	def __init__(self, size):
		
		self.n = 1
		while self.n < size:
			self.n *= 2
		self.node = [INF] * (2*self.n-1)

	def Access(self, x):
		return self.node[x+self.n-1]

	def Update(self, x, val):
		x += self.n-1
		self.node[x] = val
		while x > 0:
			x = (x-1)//2
			self.node[x] = min(self.node[2*x+1], self.node[2*x+2])
		return

	
	def Get(self, a, b, k=0, l=0, r=-1):
		if r < 0:
			r = self.n

		if a >= r or b <= l:
			return INF
		elif a <= l and b >= r:
			return self.node[k]
		else:
			vl = self.Get(a, b, 2*k+1, l, (l+r)//2)
			vr = self.Get(a, b, 2*k+2, (l+r)//2, r)
			return min(vl, vr)

n, q = map(int, input().split())
SegT = Rmin(n)
for _ in range(q):
	c, x, y = map(int, input().split())
	if c == 0:
		SegT.Update(x, y)
	else:
		print(SegT.Get(x, y+1))

Solution (Python):
class RMQ(object):
    INF = 2 ** 31 - 1

    def __init__(self, num) -> None:
        n = 1
        while n < num:
            n = n * 2
        self.n = n
        self.val = [self.INF] * (2 * n - 1)

    @staticmethod
    def merge(a: int, b: int) -> int:
        return min(a, b)

    def update(self, k: int, x: int) -> None:
        k = k + self.n - 1
        self.val[k] = x
        while k:
            k = (k - 1) // 2
            self.val[k] = self.merge(self.val[k * 2 + 1], self.val[k * 2 + 2])

    def dfs(self, beg: int, end: int, k: int, l: int, r: int) -> int:
        if (end <= l or r <= beg):
            return self.INF
        if (beg <= l and r <= end):
            return self.val[k]
        vl = self.dfs(beg, end, k * 2 + 1, l, (l + r) // 2)
        vr = self.dfs(beg, end, k * 2 + 2, (l + r) // 2, r)
        return self.merge(vl, vr)

    def query(self, beg: int, end: int) -> int:
        return self.dfs(beg, end, 0, 0, self.n)


if __name__ == "__main__":
    n, q = map(lambda x: int(x), input().split())
    rmq = RMQ(n)

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

Solution (Python):
class SegmentTree:
    def __init__(self, N, mode=min):
        n_ = 1
        
        while n_ < N:
            n_ *= 2
            
        self.n = n_
        self.mode = mode
        
        if self.mode == min:
            self.arr = [2**31-1] * (2*self.n - 1)
        elif self.mode == max:
            self.arr = [-2**31+1] * (2*self.n - 1)
    
    def update(self, k, a):
        k += self.n - 1
        self.arr[k] = a
        
        while k > 0:
            k = (k - 1) // 2
            self.arr[k] = self.mode(self.arr[2*k+1], self.arr[2*k+2])
    
    def query(self, l, r):
        L, R = l + self.n, r + self.n
        
        if self.mode == min:
            res = 2**31-1
        else:
            res = -2**31+1
        
        while L < R:
            if R & 1:
                R -= 1
                res = self.mode(res, self.arr[R-1])
            
            if L & 1:
                res = self.mode(res, self.arr[L-1])
                L += 1
            
            L >>= 1
            R >>= 1
        
        return res

n, q = map(int, input().split())
st = SegmentTree(n, min)

for _ in range(q):
    com_i, xi, yi = map(int, input().split())
    
    if com_i == 0:
        st.update(xi, yi)
    else:
        print(st.query(xi, yi+1))

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

class SegmentTree:
    def __init__(self,N,d):
        self.NN = 1
        while self.NN < N:
            self.NN *= 2
        self.SegTree = [d]*(self.NN*2-1)

    def update(self,i,x): 
        i += self.NN - 1
        self.SegTree[i] = x
        while i>0:
            i = (i-1)//2
            self.SegTree[i] = self.process(self.SegTree[i*2+1],self.SegTree[i*2+2])

    def query(self,a,b,k=0,l=0,r=None): 
        if r == None: r = self.NN
        if r <= a or b <= l: 
            return INF
        elif a <= l and r <= b : 
            return self.SegTree[k]
        else: 
            vl = self.query(a,b,k*2+1,l,(l+r)//2)
            vr = self.query(a,b,k*2+2,(l+r)//2,r)
            return(self.process(vl,vr))

    def process(self,x,y): 
        return min(x,y)


N,Q = inpl()
ST = SegmentTree(N,2**31-1)

for _ in range(Q):
    c,x,y = inpl()
    if c == 0:
        ST.update(x,y)
    else:
        print(ST.query(x,y+1))

Solution (Python):
class SegTree:
    init_val = float('inf')  

    def __init__(self, init_l):
        self.n = len(init_l)
        self.n0 = 2 ** (self.n - 1).bit_length()  
        self.l = [self.init_val] * 2 * self.n0  
        for i in range(self.n):
            self.l[i + self.n0 - 1] = init_l[i]
        for i in range(self.n0 - 2, -1, -1):
            self.l[i] = self.func(self.l[2 * i + 1], self.l[2 * i + 2])

    
    def func(self, x, y):
        return min(x, y)

    def update(self, i, new):
        i += self.n0 - 1
        self.l[i] = new
        while i + 1:
            i = (i - 1) // 2
            self.l[i] = self.func(self.l[i * 2 + 1], self.l[i * 2 + 2])

    
    def query(self, a, b):
        return self._query(a, b, 0, 0, self.n0)

    def _query(self, a, b, k, l, r):
        if r <= a or b <= l:
            return self.init_val
        if a <= l and r <= b:
            return self.l[k]
        vl = self._query(a, b, k * 2 + 1, l, (l + r) // 2)
        vr = self._query(a, b, k * 2 + 2, (l + r) // 2, r)
        return self.func(vl, vr)

n, q = map(int, input().split())
l = [2**31-1]*n
s = SegTree(l)
for i in range(q):
    c, x, y = map(int, input().split())
    if c == 0:
        s.update(x, y)
    else:
        print(s.query(x, y+1))

Solution (Python):
INF = 2 ** 31 - 1
class SegmentTree:
	def __init__(self, n):
		self.N = 1
		while self.N < n:
			self.N *= 2
		self.tree = [INF] * (self.N * 2 - 1)

	
	def update(self, i, x):
		i += self.N - 1
		self.tree[i] = x
		while i > 0:
			i = (i-1) // 2
			self.tree[i] = min(self.tree[i*2+1], self.tree[i*2+2])

	def find(self, a, b, k, l, r):
		"""[a, b), ノードkが[l, r)を担当する"""
		if r <= a or b <= l:
			return INF
		if a <= l and r <= b:
			return self.tree[k]
		else:
			c1 = self.find(a, b, 2*k+1, l, (r+l)//2)
			c2 = self.find(a, b, 2*k+2, (l+r)//2, r)
			return min(c1, c2)

import sys
input = sys.stdin.readline
from operator import itemgetter

def main():
	n, q = map(int, input().strip().split())
	st = SegmentTree(n)
	for _ in range(q):
		com, x, y = map(int, input().strip().split())
		if com:
			print(st.find(x, y+1, 0, 0, st.N))
		else:
			st.update(x, y)

if __name__ == '__main__':
	main()

Solution (Python):
class SegmentTree():
    """一点更新、区間取得クエリをそれぞれO(logN)で答えるデータ構造を構築する
    update: i番目をvalに変更する
    get_min: 区間[begin, end)の最小値を求める
    """
    def __init__(self, n):
        self.n = n
        self.INF = 2**31 - 1
        self.size = 1
        while self.size < n:
            self.size *= 2
        self.node = [self.INF] * (2*self.size - 1)

    def update(self, i, val):
        i += (self.size - 1)
        self.node[i] = val
        while i > 0:
            i = (i - 1) // 2
            self.node[i] = min(self.node[2*i + 1], self.node[2*i + 2])

    def get_min(self, begin, end):
        begin += (self.size - 1)
        end += (self.size - 1)
        s = self.INF
        while begin < end:
            if (end - 1) & 1:
                end -= 1
                s = min(s, self.node[end])
            if (begin - 1) & 1:
                s = min(s, self.node[begin])
                begin += 1
            begin = (begin - 1) // 2
            end = (end - 1) // 2
        return s

    def debug(self):
        """Segment Tree上の葉の配列を出力する"""
        return(self.node[self.size - 1: self.size - 1 + self.n])


n, q = map(int, input().split())
info = [list(map(int, input().split())) for i in range(q)]
st = SegmentTree(n)

for i in range(q):
    com, x, y = info[i]
    if com == 0:
        st.update(x, y)
    else:
        print(st.get_min(x, y + 1))

Solution (Python):

class SegmentTree:

    def __init__(self, n, fn=lambda x, y: min(x, y), unity=(1 << 31) - 1):
        self.n = 1
        while self.n < n:
            self.n *= 2

        self.arr = [unity] * (2 * self.n - 1)
        self.fn = fn
        self.unity = unity

    def update(self, i, x):
        k = self.n + i - 1
        self.arr[k] = x

        while k > 0:
            k = (k - 1) // 2
            self.arr[k] = self.fn(self.arr[2 * k + 1], self.arr[2 * k + 2])

    def query(self, l, r):
        return self._inner_query(l, r, 0, 0, self.n)

    def _inner_query(self, l, r, k, il, ir):
        if ir <= l or r <= il:
            return self.unity

        elif l <= il and ir <= r:
            return self.arr[k]

        vl = self._inner_query(l, r, k * 2 + 1, il, (il + ir) // 2)
        vr = self._inner_query(l, r, k * 2 + 2, (il + ir) // 2, ir)
        return self.fn(vl, vr)

    def __str__(self):
        return self.arr[0: 2 * self.n].__str__()

n, q = map(int, input().split())
st = SegmentTree(n)

for _ in range(q):
    com, o1, o2 = map(int, input().split())

    if com == 0:
        st.update(o1, o2)
    else:
        print(st.query(o1, o2 + 1))

Solution (Python):
import sys
input=sys.stdin.readline

import math
import sys
from collections import deque

class SegmentTree(object):

    def __init__(self,a,default):
        real_size=len(a)
        self.elem_size=elem_size=1<<math.ceil(math.log2(real_size))
        self.tree=tree=[default]*(elem_size*2-1)
        tree[elem_size:elem_size+real_size]=a
        self.default=default

        for i in range(elem_size-2,-1,-1): 
            l,r=tree[2*i+1],tree[2*i+2]
            tree[i]=l if l<r else r
    def get_value(self,x,y):
        stack=deque([(x,y,0,0,self.elem_size)])
        tree=self.tree
        ans=self.default
        while(stack):
            x,y,k,l,r=stack.pop()
            if r<=x or y<=l:
                continue
            if x<=l and r<=y:
                ans=min(ans,tree[k])
            else:
                stack.append((x,y,k*2+1,l,(l+r)//2))
                stack.append((x,y,k*2+2,(l+r)//2,r))
        return ans
    def update(self,i,x):
        i+=self.elem_size-1
        tree=self.tree
        tree[i]=x
        while(i>0):
            i=(i-1)//2
            tree[i]=min(tree[i*2+1],tree[i*2+2])


n,q=map(int,input().split())
tree=SegmentTree([2**31-1]*n,2**31-1)
for i in range(q):
    com,x,y=map(int,input().split())
    if com==0:
        tree.update(x,y)
    else:
        print(tree.get_value(x,y+1))

Solution (Python):
class SegmentTree:
    
    def __init__(self, n):
        self.n = n
        self.T = T = [2**31 - 1 for _ in range(2*n-1)]
        
    def update(self, i, x):
        i += self.n - 1
        self.T[i] = x
        while(i > 0):
            i = (i - 1) // 2
            self.T[i] = min(self.T[i*2+1], self.T[i*2+2])
            
    def find(self, a, b, k, l, r):
        if r<= a or b<= l:
            return 2**31 - 1
        if a <= l and r <= b:
            return self.T[k]
        vl = self.find(a, b, k*2+1, l,(l+r)//2)
        vr = self.find(a, b, k*2+2, (l+r)//2,r)
        return min(vl, vr)
    

n_, q = [int(i) for i in input().split()]
n = 1
while(n < n_):
    n *= 2
T = SegmentTree(n)
for _ in range(q):
    c, x, y = [int(i) for i in input().split()]
    if c == 0:
        T.update(x, y)
    else:
        print(T.find(x, y+1, 0, 0, n))

Solution (Python):
import math

line = input()
n, q = list(map(int, line.split()))
N = 1
while N < n:
    N *= 2
a = [2 ** 31 - 1 for _ in range(0, 2 * N - 1)]

def update(k, v):
    k += N - 1
    a[k] = v
    while k > 0:
        k = (k - 1) // 2
        a[k] = min(a[k * 2 + 1], a[k * 2 + 2])

def query(x, y, k, l, r):
    if r <= x or y <= l:
        return 2 ** 31 - 1
    elif x <= l and r <= y:
        return a[k]
    m = (l + r) // 2
    return min(query(x, y, k * 2 + 1, l, m), query(x, y, k * 2 + 2, m, r))

for _ in range(0, q):
    line = input()
    c, x, y = list(map(int, line.split()))
    if c == 0:
        update(x, y)
    elif c == 1:
        ans = query(x, y + 1, 0, 0, N)
        print(ans)

Solution (Python):


import sys

sys.setrecursionlimit(10 ** 9)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
INF=2**31-1

class SegTree:
    """
    以下のクエリを処理する
    1.update:  i番目の値をxに更新する
    2.get_val: 区間[l, r)の値を得る
    """
 
    def __init__(self, n, func, init):
        """
        :param n: 要素数
        :param func: 値の操作に使う関数(min, maxなど)
        :param init: 要素の初期値
        """
        n += 1
        self.n = n
        self.func = func
        self.init = init
        
        n2 = 1
        while n2 < n:
            n2 <<= 1
        self.n2 = n2
        self.tree = [self.init] * (n2 << 1)
 
    def update(self, i, x):
        """
        i番目の値をxに更新
        :param i: index(0-indexed)
        :param x: update value
        """
        i += self.n2
        self.tree[i] = x
        while i > 1:
            self.tree[i >> 1] = x = self.func(x, self.tree[i ^ 1])
            i >>= 1
 
    def get_val(self, a, b):
        """
        [a, b)の値を得る
        :param a: index(0-indexed)
        :param b: index(0-indexed)
        """
        return self._get_val(a, b, 1, 0, self.n2)
 
    def _get_val(self, a, b, k, l, r):
        """
        [a, b)の値を得る内部関数
        :param k: 現在調べている区間のtree内index
        :param l, r: kが表す区間の左右端index [l, r)
        :return: kが表す区間と[a, b)の共通区間内での最小値。共通区間を持たない場合は初期値
        """
        
        if r <= a or b <= l:
            return self.init
        
        if a <= l and r <= b:
            return self.tree[k]
        
        m = (l + r) // 2
        return self.func(
            self._get_val(a, b, k << 1, l, m),
            self._get_val(a, b, (k << 1) + 1, m, r)
        )

N,Q=MAP()
st=SegTree(N, min, INF)
for _ in range(Q):
    com,x,y=MAP()
    if com==0:
        st.update(x, y)
    else:
        print(st.get_val(x, y+1))

Solution (Python):
class SegmentTree:
    def __init__(self, n, cal, unit): 
        for k in range(40):
            if 2**k > N:
                break
        self.powers = pow(2,k)
        self.segTree = [unit]*(2*self.powers)
        self.cal = cal
        self.unit = unit
    
    def update(self, i, x):
        i += self.powers
        self.segTree[i] = x
        while i > 1:
            i //= 2
            self.segTree[i] = self.cal(self.segTree[i*2],self.segTree[i*2+1])

    def getCal(self, i, j, k=1, l=0, r=-1): 
        if r < 0: 
            r = self.powers
        if j <= l or r <= i:
            return self.unit
        if i <= l and r <= j:
            return self.segTree[k]
        return self.cal( self.getCal(i ,j, k*2, l, (l+r+1)//2) ,self.getCal(i ,j, k*2+1, (l+r+1)//2, r))

N, Q = map( int, input().split())
segmentTree = SegmentTree(N, min, 2**31-1)
for _ in range(Q):
    com, x, y = map( int, input().split())
    if com == 0:
        segmentTree.update(x,y)
    else:
        print(segmentTree.getCal(x,y+1))

Solution (Python):
class SegTree:
    
    def __init__(self, A, intv, initialize = True):
        self.N = len(A)
        self.N0 = 2**(self.N-1).bit_length()
        self.intv = intv
        if initialize:
            self.data = [intv]*(self.N0-1) + A + [intv]*(self.N0 - self.N + 1)
            for i in range(self.N0-2, -1, -1):
                self.data[i] = min(self.data[2*i+1], self.data[2*i+2]) 
        else:
            self.data = [intv]*(2*self.N0)
    
    def segf(self, a, b):
        return min(a, b)
    
    def update(self, k, x):
        k += self.N0-1
        self.data[k] = x
        while k >= 0 :
            k = (k-1)//2
            self.data[k] = min(self.data[2*k+1], self.data[2*k+2])
    
    def query(self, l, r):
        L, R = l+self.N0, r+self.N0
        s = self.intv
        while L < R:
            if R & 1:
                R -= 1
                s = min(s, self.data[R-1])
            if L & 1:
                
                s = min(s, self.data[L-1])
                L += 1
            L >>= 1
            R >>= 1
        return s

import sys
N, Q = map(int, input().split())
T = SegTree([0]*N, 2**31-1, False)
for _ in range(Q):
    qt, x, y = map(int, sys.stdin.readline().split())
    if qt:
        print(T.query(x, y+1))
    else:
        T.update(x, y)

Solution (Python):
class SegmentTree:
  def __init__(self, l, func=min, init_val=float("inf")):
    self.func = func
    self.init_val = init_val
    n = 1
    while n < len(l):
      n *= 2
    self.nodes = [init_val for _ in range(2*n-1)]
    self.n = n
    for i in range(len(l)):
      self.nodes[i+n-1] = l[i]
    for i in range(n-2, -1, -1):
      self.nodes[i] = self.func(self.nodes[2*i+1], self.nodes[2*i+2])

  def update(self, x, val):
    x += self.n - 1
    self.nodes[x] = val
    while x > 0:
      x = (x - 1) // 2
      self.nodes[x] = self.func(self.nodes[2*x+1], self.nodes[2*x+2])

  def get(self, a, b):
    return self._get(a, b)

  def _get(self, a, b, k=0, l=0, r=-1):
    if (r < 0):
      r = self.n
    if (r <= a or b <= l):
      return self.init_val
    if (a <= l and r <= b):
      return self.nodes[k]
    return self.func(
      self._get(a, b, 2*k+1, l, (l + r) // 2),
      self._get(a, b, 2*k+2, (l + r) // 2, r)
    )

n, q = map(int, input().split())
alist = [pow(2, 31)-1 for _ in range(n)]
minsegt = SegmentTree(alist, init_val=pow(2, 31)-1)
for _ in range(q):
  c, x, y = map(int, input().split())
  if c == 0:
    minsegt.update(x, y)
  else:
    print(minsegt.get(x, y+1))

Solution (Python):
class RMQ:
  def __init__(self,n,e):
    self.n = 2**((n-1).bit_length())
    self.e = e
    self.d = [e]*(self.n<<1)
  
  def update(self,k,x):
    k += self.n-1
    self.d[k] = x
    while k > 0:
      k = (k-1)>>1
      self.d[k] = min(self.d[(k<<1)+1],self.d[(k<<1)+2])
    
  def query(self,l,r):
    L = l+self.n; R = r+self.n
    s = self.e
    while L < R:
      if R & 1:
        R -= 1
        s = min(s,self.d[R-1])
      if L & 1:
        s = min(s,self.d[L-1])
        L += 1
      L >>= 1; R >>= 1
    return s

[n,q] = list(map(int,input().split()))
rmq = RMQ(n,(1<<31)-1)
for i in range(q):
	[com,x,y] = list(map(int,input().split()))
	if com == 0:
		rmq.update(x,y)
	else:
		print(rmq.query(x,y+1))

Solution (Python):
INF = 2**31-1
class SegmentTree():
    def __init__(self, N):
        self.N0 = 2**(N-1).bit_length()
        self.data = [INF]*((2*self.N0)+1)

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

    
    def query(self, l, r):
        L = l + self.N0; R = r + self.N0
        s = INF
        while L < R:
            if R & 1:
                R -= 1
                s = min(s, self.data[R-1])

            if L & 1:
                s = min(s, self.data[L-1])
                L += 1
            L >>= 1; R >>= 1
        return s


N, Q = map(int, input().split())
segtree = SegmentTree(N)
segtree.data

"""
for i in range(1, N+1):
    update(i, a[i])
"""
for i in range(Q):
    q, l, r = map(int, input().split())
    if q == 1:
        print(segtree.query(l, r+1))
    else:
        segtree.update(l, r)

Solution (Python):
INF = 2**31-1
n, q = map(int, input().split())
size = 2**((n-1).bit_length())
seg_tree = [INF]*(size*2)

import sys
input = sys.stdin.readline

def update(i, x):
    ind = size+i
    seg_tree[ind] = x
    while ind>1:
        ind >>= 1
        left = seg_tree[ind*2]
        right = seg_tree[ind*2+1]
        seg_tree[ind] = min(left, right)
    
def find(s,t):
    L = s+size
    R = t+size
    ret = INF
    while L<R:
        if R&1:
            R-=1
            ret = min(ret, seg_tree[R])
        if L&1:
            ret = min(ret, seg_tree[L])
            L+=1
        L=L>>1
        R=R>>1
    return ret

for _ in range(q):
    com, x, y = map(int, input().split())
    if not com:
        update(x, y)
    else:
        print(find(x,y+1))

Solution (Python):

class RangeMinimumQuery:
    def __init__(self, n, inf=2 ** 31 - 1):
        self.n = 1 << (n - 1).bit_length()
        self.INF = inf
        self.segtree = [self.INF] * (2 * self.n)

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

    
    def query(self, l, r):
        L, R = l + self.n, r + self.n
        s = self.INF
        while L < R:
            if L & 1:
                s = min(s, self.segtree[L])
                L += 1

            if R & 1:
                s = min(s, self.segtree[R - 1])
                R -= 1

            L >>= 1
            R >>= 1

        return s


N, Q = map(int, input().split())
RMQ = RangeMinimumQuery(N)
for q in range(Q):
    cmd, x, y = map(int, input().split())
    if cmd == 0:
        RMQ.update(x, y)

    if cmd == 1:
        print(RMQ.query(x, y + 1))

Solution (Python):
import sys
sys.setrecursionlimit(10000)

INF = 2147483647



def initRMQ(n, D):
    n_ = 1
    
    while n_ < n:
        n_ *= 2
    
    for i in range(2*n_ - 1):
        D.append(INF)

    return n_


def update(k, a):
    k += n_ - 1  
    D[k] = a
    while k != 0:
        k = int((k - 1) / 2)
        D[k] = min(D[k*2 + 1], D[k*2 + 2])


def findMin(qlow, qhigh):
    return query(qlow, qhigh + 1, 0, 0, n_)


def query(qlow, qhigh, k, l, r):
    
    if r <= qlow or qhigh <= l:
        return INF

    if qlow <= l and r <= qhigh:
        return D[k]

    mid = (l + r) // 2
    vl = query(qlow, qhigh, k*2 + 1, l, mid)
    vr = query(qlow, qhigh, k*2 + 2, mid, r)

    return min(vl, vr)


if __name__ == '__main__':
    n, q = map(int, input().split())

    D = []
    n_ = initRMQ(n, D)

    for _ in range(q):
        
        c, x, y = map(int, input().split())

        if c == 0:
            update(x, y)

        else:
            print(findMin(x, y))

Solution (Python):
answer=[]
D=[]
def initRMQ(nn):
    global n
    n = 1
    while n < nn:
        n*=2
    for i in range(2*n-1):
        D.append(2147483647)

def update(k,a):
    k += n-1
    D[k] = a
    while k>0:
        k = (k-1)//2
        D[k] = min(D[k*2+1] , D[k*2+2])
        
def findMin(a,b):
    return query(a,b+1,0,0,n)

def query(a,b,k,l,r):
    if r <= a or b <= l:
        return 2147483647
    if a <= l and r <= b:
        return D[k]
    
    vl = query(a, b, (k*2)+1, l, (l+r)//2)
    vr = query(a, b, (k*2)+2, (l+r)//2, r)
    return min(vl,vr)


inn,q = map(int,input().split())
initRMQ(inn)
while True:
    try:
        o,x,y = map(int,input().split())
    except:
        break
    else:
        if o == 0:
            update(x,y)
        else:
            answer.append(findMin(x,y))
            
for i in range(len(answer)):
    print(answer[i])

Solution (Python):

INF = 2**31 -1
n, p = list(map(int, input().split()))

temp = 1
while temp < n:
  temp *= 2

lis = [INF for i in range(2*temp-1)]

def updata(x, y):
  x += temp - 1
  lis[x] = y
  while x > 0:
    x = (x-1) // 2
    
    lis[x] = min(lis[x*2+1], lis[x*2+2])

def findmin(x, y):
  return query(x, y+1, 0, 0, temp)

def query(a, b, k, l, r):
  
  if r <= a or b <= l:
    return INF

  if a <= l and r <= b:
    return lis[k]
  
  vl = query(a, b, k*2+1, l, (l+r)//2)
  vr = query(a, b, k*2+2, (l+r)//2, r)
  return min(vl, vr)


for i in range(p):
  oper, x, y = list(map(int, input().split()))
  
  if oper == 0:
    updata(x, y)
  else: 
    print(findmin(x, y))

Solution (Python):
import math


def update(numlist,i):
  if i<0:
    return
  if i==0:
    numlist[i]=min(numlist[2*i+1],numlist[2*i+2])
    return
  numlist[i]=min(numlist[2*i+1],numlist[2*i+2])
  update(numlist,(i-1)//2)
  return

def find(numlist,x,y,k,minimum,maximum,MAX):
  if x>=maximum or y<minimum:
    return MAX
  if x<=minimum and maximum-1<=y:
    return numlist[k]
  else:
    L=find(numlist,x,y,k*2+1,minimum,(maximum+minimum)//2,MAX)
    R=find(numlist,x,y,k*2+2,(maximum+minimum)//2,maximum,MAX)
    return (min(L,R))
    
  

n,q=map(int,input().split())
L2n=math.ceil(math.log2(n))
zero=2**(L2n)-1
MAX=2**31-1
numlist=[MAX]*(2**(L2n+1)-1)
resultlist=[]

for _ in range(0,q):
  com,x,y=map(int,input().split())
  if com:
    resultlist.append(find(numlist,x,y,0,0,2**L2n,MAX))
  else:
    numlist[zero+x]=y
    update(numlist,(zero+x-1)//2)

for x in resultlist:
  print (x)

Solution (Python):


import sys

INF = 2 ** 31 - 1
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]


class SegmentTree:
    __slots__ = ['node', 'size']

    def __init__(self, n_):
        self.size = 2 ** n_.bit_length()
        self.node = [INF] * (2 * self.size)

    
    def update(self, k, a):
        k += self.size - 1
        self.node[k] = a
        
        while k >= 0:
            k = (k - 1) // 2
            self.node[k] = min(self.node[k * 2 + 1], self.node[k * 2 + 2])

    
    def query(self, a, b):
        l, r = a + self.size, b + self.size
        res = INF
        while l < r:
            if r & 1:
                r -= 1
                res = min(res, self.node[r - 1])

            if l & 1:
                res = min(res, self.node[l - 1])
                l += 1

            l >>= 1
            r >>= 1
        return res


n, q = LI()
sgt = SegmentTree(n)

for _ in range(q):
    c, x, y = LI()

    if c == 0:
        sgt.update(x, y)
    else:
        print(sgt.query(x, y + 1))