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):
oldn,q = map(int , input().split())
INF = 2147483647
n = 1

while(n < oldn) :
    n *= 2
dat = []
for i in range(2*n-1):
    dat.append(INF)

def updata(k , a): 
    k += (n-1)
    dat[k] = a
    while (k > 0):
        k = (k-1) // 2 
        dat[k] = min(dat[2*k+1],dat[2*k+2])



def query(a,b,k,l,r):
    if(r <= a) or (b <= l) : return INF
    if(a <=l) and (r <= b) : return dat[k]
    v1 = query(a,b,2*k+1,l,(l+r)/2)
    v2 = query(a,b,2*k+2,(l+r)/2,r)
    return min(v1,v2)

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

Solution (Python):

class seg_tree:
    def __init__(self,n,minimum=True):
        self.inf = 2**31-1
        self.size = 2**(len(bin(n-1))-2)*2-1
        self.minimum = minimum
        if self.minimum:
            self.tree = [self.inf for i in range(self.size)]
        else:
            self.tree = [-1 for i in range(self.size)]
     
    def data(self):
        return self.tree[self.size//2:]
 
    def update(self,i,x):
        i=self.size//2+i
        self.tree[i]=x
        if self.minimum:
            while 1:
                i=(i-1)//2
                self.tree[i]=min(self.tree[i*2+1],self.tree[i*2+2])
                if i<=0:
                    break
        else:
            while 1:
                i=(i-1)//2
                self.tree[i]=max(self.tree[i*2+1],self.tree[i*2+2])
                if i<=0:
                    break
 
    def _mincheck(self,s,t,l,r,_p=0):
        if s<=l and r<=t:
            return self.tree[_p]
        elif r<s or t<l:
            return self.inf
        else:
            return min(self._mincheck(s,t,l,l+(r-l)//2,_p*2+1),self._mincheck(s,t,l+(r-l)//2+1,r,_p*2+2))
     
    def _maxcheck(self,s,t,l,r,_p=0):
        if s<=l and r<=t:
            return self.tree[_p]
        elif r<s or t<l:
            return -1
        else:
            return max(self._maxcheck(s,t,l,l+(r-l)//2,_p*2+1),self._maxcheck(s,t,l+(r-l)//2+1,r,_p*2+2))
 
    def find(self,s,t):
        if self.minimum:
            return self._mincheck(s,t,0,self.size//2)
        else:
            return self._maxcheck(s,t,0,self.size//2)
 
n,q=map(int,input().split())
st=seg_tree(n)
ans=[]
for i in range(q):
    c,x,y=map(int,input().split())
    if c:
        ans.append(st.find(x,y))
    else:
        st.update(x,y)
print(*ans,sep='\n')

Solution (Python):
n,q=map(int,input().split())
Q=[list(map(int,input().split())) for i in range(q)]


for i in range(30):
    if n<=1<<i:
        seg_el=1<<i
        break

SEG=[(1<<31)-1]*(2*seg_el-1)

def update(n,x,seg_el):
    i=n+seg_el-1
    SEG[i]=x
    i=(i-1)//2
    
    while i>=0:
        SEG[i]=min(SEG[i*2+1],SEG[i*2+2])
        i=(i-1)//2
        

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

for com,x,y in Q:
    if com==0:
        update(x,y,seg_el)
    else:
        print(getvalues(x,y+1,0,0,seg_el))

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


class SegmentTree(object):
    INT_MAX = (1 << 31) - 1

    def __init__(self, n_):
        n = 1
        while n < n_:
            n *= 2
        self._tree = [self.INT_MAX] * (n * 2 - 1)
        self.num_elems = n


    def update(self, k, a):
        
        k += self.num_elems - 1
        self._tree[k] = a

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

    def query(self, a, b, k, l, r):
        if r <= a or b <= l:
            return self.INT_MAX
        
        if (a <= l and r <= b):
            return self._tree[k]
        else:
            m = (l + r) // 2
            vl = self.query(a, b, 2 * k + 1, l, m)
            vr = self.query(a, b, 2 * k + 2, m, r)
            
            return min(vl, vr)
    

n, q = [int(elem) for elem in fin().split()]
segtree = SegmentTree(n)

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

queries = tuple(tuple(int(elem) for elem in fin().split()) for _ in range(q))

for c, x, y in queries:
    if c == 0:
        segtree.update(x, y)
    else:
        print(segtree.query(x, y + 1, 0, 0, ceil_exp_2))

Solution (Python):
class RMQ:
    INF = int((1<<31)-1)
    
    def __init__(self, n_:int):
        """param: n_(int) 葉の要素数"""
        
        n = 1
        while n<n_: n*=2
        self.n = n
        
        self.dat = [self.INF]*(2*n-1)
    
    def update(self, k:int, a:int):
        k += self.n - 1
        self.dat[k] = a
        
        while k>0:
            k = (k-1)//2
            self.dat[k] = min(self.dat[2*k+1], self.dat[2*k+2])
            
    def dfs(self, a:int, b:int, k:int, l:int, r:int):
        """
        param a,b(int): 区間[a,b)
        param k(int):   節点の番号
        param l,r(int): 節点kが区間[l,r)に対応"""
        if r<=a or b<=l: return self.INF
        
        if a<=l and r<=b: 
            return self.dat[k]
        else:
            vl = self.dfs(a, b, 2*k+1, l, (l+r)//2)
            vr = self.dfs(a, b, 2*k+2, (l+r)//2, r)
            return min(vl, vr)
    
    def query(self, a:int, b:int):
        return self.dfs(a, b, 0, 0, self.n)
    

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

Solution (Python):
class RmQ_segment_tree:
    """0 indexed"""

    def __init__(self, init_num, n):
        
        
        
        self.ex = 0
        while(2 ** self.ex < n):
            self.ex += 1
        self.bottom = 2 ** self.ex - 1
        self.tree = [init_num for _ in range(2 ** (self.ex + 1) - 1)]

    def __str__(self):
        tmp = "tree structure\n"
        tree = str(self.tree)
        return tmp + tree + "\n"

    def update(self, position, new):
        
        
        chi = self.bottom + position
        self.tree[chi] = new
        for _ in range(self.ex):
            par = (chi - 1) // 2
            ano_chi = [chi + 1, chi - 1][chi % 2 == 0]
            self.tree[par] = min(self.tree[chi], self.tree[ano_chi])
            chi = par
        return True

    def find(self, left, right):
        left = self.bottom + left
        right = self.bottom + right
        ret = min(self.tree[left], self.tree[right])
        while(left != right):
            if left % 2 == 0:
                ret = min(self.tree[left], ret)
                left += 1
                continue
            if right % 2 == 1:
                ret = min(self.tree[right], ret)
                right -= 1
                continue

            left = (left - 1) // 2
            right = (right - 1) // 2
        ret = min(ret, self.tree[left])
        return ret


init_num = 2 ** 31 - 1
n, q = map(int, input().split())
RmQ = RmQ_segment_tree(init_num, n)

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

    if com == 0:
        RmQ.update(x, y)
        
    else:
        print(RmQ.find(x, y))

Solution (Python):
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop


BIG_NUM = 2147483647
HUGE_NUM = 9999999999999999
MOD = 1000000007
EPS = 0.000000001


global N
global table

def MIN(A,B):
    if A <= B:
        return A
    else:
        return B


def init(first_N):
    global N
    while N < first_N:
        N *= 2

def update(loc,value):
    global N
    loc += N-1

    table[loc] = value

    if N == 1:
        return

    parent = (loc-1)//2

    while True:
        table[parent] = MIN(table[2*parent+1],table[2*parent+2])

        if parent == 0:
            break

        parent = (parent-1)//2


def query(search_left,search_right,node_id,node_left,node_right):

    if search_right < node_left or search_left > node_right:
        return BIG_NUM
    if search_left <= node_left and search_right >= node_right:
        return table[node_id]
    else:
        left_min = query(search_left,search_right,2*node_id+1,node_left,(node_left+node_right)//2)
        right_min = query(search_left,search_right,2*node_id+2,(node_left+node_right)//2+1,node_right)
        return MIN(left_min,right_min)



first_N,num_query = map(int,input().split())
N = 1
init(first_N)

table = [None]*(2*N-1)

for i in range(2*N-1):
    table[i] = BIG_NUM


for loop in range(num_query):
    command,left,right = map(int,input().split())

    if command == 0:

        update(left,right)

    else:
        print("%d"%(query(left,right,0,0,N-1)))

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

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 SegTree():
    def __init__(self, node:int):
        self.n = node
        self.bit = len(bin(self.n-1)) - 2
        self.bottom = 2**self.bit
        
        if self.n == 1:
            self.bottom = 1
            
        self.segtree = [0]*(2*self.bottom-1)
        
        
    def fill(self, n:int):
        self.segtree = [n]*(2*self.bottom-1)
        
    def update(self, idx:int, x:int):
        idx += (self.bottom-1)
        self.segtree[idx] = x
        while idx > 0:
            k = (idx-1) >> 1
            self.segtree[k] = min(self.segtree[2*k+1],
                                  self.segtree[2*k+2])
            idx = k
            
            
    def find(self, left:int, right:int, idx:int, l:int, r:int):
        if left <= l and r <= right:
            return self.segtree[idx]

        elif l >= right or r <= left:
            return 10**10
        
        else:
            return min(self.find(left, right, 2*idx+1, l, (l+r)//2),
                       self.find(left, right, 2*idx+2, (l+r)//2, r))
        
            
n,q = li()
com = []
xy = []
for _ in range(q):
    c,x,y = li()
    com.append(c)
    xy.append((x, y))
    
segtree = SegTree(n)
segtree.fill(2**31-1)
    
for c, (x,y) in zip(com, xy):
    if c == 0:
        segtree.update(x, y)
        
    else:
        print(segtree.find(x, y+1, 0, 0, segtree.bottom))

Solution (Python):
import sys
readline = sys.stdin.readline
write = sys.stdout.write
N, Q = map(int, readline().split())

N0 = 2**(N-1).bit_length()
INF = 2**31-1
data = [INF]*(2*N0)
def update(k, x):
    k += N0-1
    data[k] = x
    while k >= 0:
        k = (k - 1) // 2
        data[k] = min(data[2*k+1], data[2*k+2])
def query(l, r):
    L = l + N0; R = r + N0
    s = INF
    while L < R:
        if R & 1:
            R -= 1
            s = min(s, data[R-1])

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


ans = []
for q in range(Q):
    t, x, y = map(int, readline().split())
    if t:
        ans.append(str(query(x, y+1)))
    else:
        update(x, y)
write("\n".join(ans))
write("\n")