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: Wrong Answer

Solution code:
import bisect
import collections
import heapq
import itertools
import operator
import sys


def main():
    int_max = 2 ** 31 - 1
    n, q = map(int, sys.stdin.readline().split())
    dat = [int_max] * 131072 * 2

    def update(i, x):
        i += n - 1
        dat[i] = x
        while i > 0:
            i = (i - 1) // 2
            dat[i] = min(dat[i * 2 + 1], dat[i * 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)

    for _ in range(q):
        com, x, y = map(int, sys.stdin.readline().split())
        if com == 0:
            update(x, y)
        elif com == 1:
            print(query(x, y + 1, 0, 0, n))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin


def main(init=int(2**31-1)):
    n, q = (int(s) for s in stdin.readline().split())

    a = [init] * n
    i = init
    v = init

    for _ in range(q):
        com, x, y = (int(s) for s in stdin.readline().split())
        if com:
            if x <= i <= y:
                print(v)
            else:
                print(min(a[x:y+1]))
        else:
            a[x] = y
            if y < v:
                i = x
                v = y


main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin


def main(init=int(2**31-1)):
    n, q = (int(s) for s in stdin.readline().split())

    a = [init] * n
    i = init
    v = init

    for _ in range(q):
        com, x, y = (int(s) for s in stdin.readline().split())
        if com:
            if x <= i <= y:
                print(v)
            else:
                print(min(a[x:y+1]))
        else:
            a[x] = y
            if y < v:
                i = x
                v = y
            elif x == i and y > v:
                i = init
                v = init


main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin


def main(init=int(2**31-1)):
    n, q = (int(s) for s in stdin.readline().split())

    a = [init] * n
    s = t = m = init

    for _ in range(q):
        com, x, y = (int(s) for s in stdin.readline().split())
        if com:
            if not (x <= s and t <= y):
                s = x
                t = y
                m = min(a[x:y+1])
            print(m)
        else:
            a[x] = y
            if s <= x <= t:
                if y <= m:
                    m = y
                else:
                    s = t = m = init

main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin


def main(init=int(2**31-1)):
    n, q = (int(s) for s in stdin.readline().split())

    a = [init] * n
    s = t = m = init

    for _ in range(q):
        com, x, y = (int(s) for s in stdin.readline().split())
        if com:
            if not (t <= y and x <= s):
                s = x
                t = y
                if x == y:
                    m = a[x]
                else:
                    m = min(a[x:y+1])
            print(m)
        else:
            a[x] = y
            if s <= x <= t and y <= m:
                m = y
            else:
                s = t = init


main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin


def main(init=int(2**31-1)):
    n, q = (int(s) for s in stdin.readline().split())

    a = [init] * n
    S = set()

    for _ in range(q):
        com, x, y = (int(s) for s in stdin.readline().split())
        if com:
            if x == y:
                m = a[x]
            else:
                try:
                    m = min(a[i] for i in S if x <= i <= y)
                except ValueError:
                    m = min(a[x:y+1])
            print(m)
        else:
            a[x] = y
            try:
                i = a[x-1]
                j = a[x+1]
            except IndexError:
                pass
            else:
                if i > y < j:
                    S.add(x)
                    S.discard(x-1)
                    S.discard(x+1)
                else:
                    S.discard(x)


main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin


def main(init=int(2**31-1)):
    n, q = (int(s) for s in stdin.readline().split())

    a = [init] * n
    S = set()

    for _ in range(q):
        com, x, y = (int(s) for s in stdin.readline().split())
        if com:
            if x == y:
                m = a[x]
            else:
                try:
                    m = min(a[i] for i in S if x <= i <= y)
                except ValueError:
                    m = min(a[x:y+1])
            print(m)
        else:
            a[x] = y
            try:
                f = y < a[x-1]
            except IndexError:
                f = True

            try:
                g = y < a[x+1]
            except IndexError:
                g = True

            S.discard(x)
            if f and g:
                S.add(x)
                S.discard(x-1)
                S.discard(x+1)


main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin


def main(init=int(2**31-1)):
    n, q = (int(s) for s in stdin.readline().split())

    a = [init] * n
    S = set()

    for _ in range(q):
        com, x, y = (int(s) for s in stdin.readline().split())
        if com:
            if x == y:
                m = a[x]
            else:
                try:
                    m = min(a[i] for i in (S | {x, y}) if x <= i <= y)
                except ValueError:
                    m = min(a[x:y+1])
            print(m)
        else:
            a[x] = y
            try:
                f = y < a[x-1]
            except IndexError:
                f = True

            try:
                g = y < a[x+1]
            except IndexError:
                g = True

            S.discard(x)
            if f and g:
                S.add(x)
                S.discard(x-1)
                S.discard(x+1)


main()

Submission status: Time Limit Exceeded

Solution code:

MAX = 2**31-1


def run():
    n, q = [int(i) for i in input().split()]
    seq = [MAX for _ in range(n)]

    for _ in range(q):
        com, x, y = [int(i) for i in input().split()]
        if com == 0:
            seq[x] = y
        elif com == 1:
            print(min(seq[x:y+1]))
        else:
            raise ValueError('invalid command: {}'.format(com))


if __name__ == '__main__':
    run()

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
default = 2**31 - 1

mindict = {}
answer_stk = []

for i in range(q) :
    query, x, y = map(int, input().split())
    
    if query == 0 :
        mindict[x] = y
    else :
        min_between = default
        for k in mindict.keys() :
            if k >= x and k <= y :
                min_between = min(min_between, mindict[k])
                
        answer_stk.append(min_between)
        
for a in answer_stk :
    print(a)

Submission status: Time Limit Exceeded

Solution code:

A = []

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

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

if __name__ == "__main__":
    n, q = map(int, input().split())
    A = [2**31 - 1] * n 
    for i in range(q):
        com, x, y = map(int, input().split())
        if com == 0:
            update(x, y)
        else:
            m = find(x, y)
            print(m)

Submission status: Time Limit Exceeded

Solution code:
A = []
def update(i, x):
    A[i] = x
    
def find(x,y):
    print(min(A[x:y+1]))

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

for i in range(n):
    A.append(2**31-1)
    
for i in range(q):
    com, x, y = [int(i) for i in input().split()]
    if com == 0:
        update(x, y)
    else:
        find(x,y)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
class SqrtDecomposition:
    # RMQ用平方分割
    
    # n:要素数 init:配列初期値
    def __init__(self,n,init=0):
        self.data=[init for i in range(n)]
        self.sqrt_n=int(n**0.5)+1
        self.bucket=[init for i in range(self.sqrt_n)]
    
    # x を y にする
    def update(self,x,y):
        self.data[x] = y
        tmp = self.data[x//self.sqrt_n * self.sqrt_n]
        for i in range(x//self.sqrt_n * self.sqrt_n, min(x//self.sqrt_n * self.sqrt_n + self.sqrt_n, n)):
            if tmp > self.data[i]:
                tmp = self.data[i]
        self.bucket[x//self.sqrt_n] = tmp
    
    # [x,y) の最小を求める
    def find(self,x,y):
        tmp = 10**19
        for i in range(self.sqrt_n):
            l,r=i*self.sqrt_n,(i+1)*self.sqrt_n
            if r <= x or y <= l :
                continue
            if x <= l and r <= y :
                tmp = min(tmp, self.bucket[i]);
            else:
                for j in range(max(x, l),min(y, r)):
                    tmp = min(tmp, self.data[j]);
        return tmp


n,q = map(int,input().split())
sd=SqrtDecomposition(n,2**31-1)
for i in range(q):
    c,x,y=map(int,input().split())
    if c==0:
        sd.update(x,y)
    else:
        print(sd.find(x,y+1))

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
class SqrtDecomposition:
    # RMQ用平方分割
    
    # n:要素数 init:配列初期値
    def __init__(self,n,init=0):
        self.data=[init for i in range(n)]
        #self.sqrt_n=int(n**0.5)+1
        self.sqrt_n=512
        self.bucket=[init for i in range(self.sqrt_n)]
    
    # x を y にする
    def update(self,x,y):
        self.data[x] = y
        tmp = self.data[x//self.sqrt_n * self.sqrt_n]
        for i in range(x//self.sqrt_n * self.sqrt_n, min(x//self.sqrt_n * self.sqrt_n + self.sqrt_n, n)):
            if tmp > self.data[i]:
                tmp = self.data[i]
        self.bucket[x//self.sqrt_n] = tmp
    
    # [x,y) の最小を求める
    def find(self,x,y):
        tmp = 10**19
        for i in range(self.sqrt_n):
            l,r=i*self.sqrt_n,(i+1)*self.sqrt_n
            if r <= x or y <= l :
                continue
            if x <= l and r <= y :
                tmp = min(tmp, self.bucket[i]);
            else:
                for j in range(max(x, l),min(y, r)):
                    tmp = min(tmp, self.data[j]);
        return tmp


n,q = map(int,input().split())
sd=SqrtDecomposition(n,2**31-1)
for i in range(q):
    c,x,y=map(int,input().split())
    if c==0:
        sd.update(x,y)
    else:
        print(sd.find(x,y+1))

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import sys
input=lambda : sys.stdin.readline().rstrip()

class SqrtDecomposition:
    # RMQ用平方分割
    
    # n:要素数 init:配列初期値
    def __init__(self,n,init=0):
        self.data=[init for i in range(n)]
        #self.sqrt_n=int(n**0.5)+1
        self.sqrt_n=int(n**0.5)+1
        self.bucket=[init for i in range(self.sqrt_n)]
    
    # x を y にする
    def update(self,x,y):
        self.data[x] = y
        tmp = self.data[x//self.sqrt_n * self.sqrt_n]
        for i in range(x//self.sqrt_n * self.sqrt_n, min(x//self.sqrt_n * self.sqrt_n + self.sqrt_n, n)):
            if tmp > self.data[i]:
                tmp = self.data[i]
        self.bucket[x//self.sqrt_n] = tmp
    
    # [x,y) の最小を求める
    def find(self,x,y):
        tmp = 10**19
        for i in range(self.sqrt_n):
            l,r=i*self.sqrt_n,(i+1)*self.sqrt_n
            if r <= x or y <= l :
                continue
            if x <= l and r <= y :
                tmp = min(tmp, self.bucket[i]);
            else:
                for j in range(max(x, l),min(y, r)):
                    tmp = min(tmp, self.data[j]);
        return tmp


n,q = map(int,input().split())
sd=SqrtDecomposition(n,2**31-1)
for i in range(q):
    c,x,y=map(int,input().split())
    if c==0:
        sd.update(x,y)
    else:
        print(sd.find(x,y+1))

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,raw_input().split())
Ai = 2**31-1
A = [Ai for i in range(n)]
for i in range(q):
    com,xi,yi = map(int,raw_input().split())
    if com==0: # update(xi,yi) 
        A[xi] = yi
    elif com==1:# find(xi,yi)
        print min(A[xi:yi+1])

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,raw_input().split())
Ai = 2**31-1
A = [Ai]*n
for i in xrange(q):
    com,xi,yi = map(int,raw_input().split())
    if com: # find(xi,yi)
        print min(A[xi:yi+1])
    else: # update(xi,yi) 
        A[xi] = yi

Submission status: Time Limit Exceeded

Solution code:
# Range Minimum Query
n,q = map(int,raw_input().split())
A = [2**31-1]*n
for i in range(q):
    comi,xi,yi = map(int,raw_input().split())
    if comi:
        print min(A[xi:yi+1])
    else:
        A[xi]=yi

Submission status: Time Limit Exceeded

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]*1001
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: Time Limit Exceeded

Solution code:
def main():
    n, q = map(int, raw_input().split())
    a = [2 ** 31 - 1] * n
    for _ in xrange(q):
        com, x, y = map(int, raw_input().split())
        if com:
            print min(a[x:y+1])
        else:
            a[x] = y


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,raw_input().split())
a_list=[2**31-1 for x in range(n)]
for i in range(q):
	function=map(int,raw_input().split())
	if function[0]==0:
		a_list[function[1]]=function[2]
	else:
		print(min(a_list[function[1]:function[2]+1]))

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())

l = [2 ** 31 - 1] * n

while q:
    op, s, t = map(int, input().split())
    if op:
        print(min(l[s:t + 1]))
    else:
        l[s] = t
    q -= 1

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())

A = [2**31-1] * n

for _ in range(q):
    com, x, y = map(int, input().split())
    if com == 0:
        A[x] = y

    if com == 1:
        print(min(A[x : y+1]))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

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

A = deque([2**31-1] * n)

for _ in range(q):
    com, x, y = map(int, input().split())
    if com == 0:
        A[x] = y

    if com == 1:
        print(min([A[i] for i in range(x, y+1)]))

Submission status: Time Limit Exceeded

Solution code:
class RMQ():
    def __init__(self, array=None):
        if array is None:
            n,q = map(int, input().split())
            array = [2**31-1 for i in range(n)]
            self.array = array
            for j in range(q):
                com, x, y = map(int, input().split())
                if com == 0:
                    self.update(x, y)
                elif com == 1:
                    self.find(x, y)

    def find(self, s, t):
        minimum = min(self.array[s:t+1])
        print(minimum)

    def update(self, i, x):
        self.array[i] = x
rmq = RMQ()
rmq

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
array = [2 ** 31 - 1 for i in range(n)]

def find(s, t):
    minimum = min(array[s:t + 1])
    print(minimum)

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

for j in range(q):
    com, x, y = map(int, input().split())
    if com == 0:
        update(x, y)
    elif com == 1:
        find(x, y)

Submission status: Time Limit Exceeded

Solution code:
#input = ["3 5","0 0 1","0 1 2","0 2 3","1 0 2","1 1 2"]
#input = ["1 3","1 0 0","0 0 5","1 0 0"]
#input = ["2 15","1 0 1","1 0 0","1 1 1","0 0 2","1 0 1","1 0 0","1 1 1","0 1 1","1 0 1","1 0 0","1 1 1","0 1 5","1 0 1","1 0 0","1 1 1"]
output=[]

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

n=int(l[0])
a = range(0,n)
for i in range(0,n):
	a[i] = 2 ** 31 - 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])
	else:
		output.append(min(a[int(l[1]):int(l[2])+1]))

for i in output:
	print i

Submission status: Time Limit Exceeded

Solution code:
#input = ["3 5","0 0 1","0 1 2","0 2 3","1 0 2","1 1 2"]
#input = ["1 3","1 0 0","0 0 5","1 0 0"]
#input = ["2 15","1 0 1","1 0 0","1 1 1","0 0 2","1 0 1","1 0 0","1 1 1","0 1 1","1 0 1","1 0 0","1 1 1","0 1 5","1 0 1","1 0 0","1 1 1"]
output=[]

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

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

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])
	else:
		output.append(min(a[int(l[1]):int(l[2])+1]))

for i in output:
	print i

Submission status: Time Limit Exceeded

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

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

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])
	else:
		print min(a[int(l[1]):int(l[2])+1])

Submission status: Time Limit Exceeded

Solution code:
#input = ["3 5","0 0 1","0 1 2","0 2 3","1 0 2","1 1 2"]
#input = ["1 3","1 0 0","0 0 5","1 0 0"]
#input = ["2 15","1 0 1","1 0 0","1 1 1","0 0 2","1 0 1","1 0 0","1 1 1","0 1 1","1 0 1","1 0 0","1 1 1","0 1 5","1 0 1","1 0 0","1 1 1"]
#input = ["1 5","1 0 0","0 0 5","1 0 0","0 0 8","1 0 0"]

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==1:
		m = min(a[int(l[1]):int(l[2])+1])
		print m
	else:
		print m

Submission status: Time Limit Exceeded

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]:
		change = l[1]+l[2]
		print m
	else:
		m = min(a[int(l[1]):int(l[2])+1])
		print m

Submission status: Time Limit Exceeded

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

n = int(l[0])
a = [2147483647]*n
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: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())

A = [2147483647] * n

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

def find(s, t):
    print(min(A[s:t+1]))


for i in range(q):
    com, x, y = map(int, input().split())
    if com == 0:
        update(x, y)
    else:
        find(x, y)

Submission status: Time Limit Exceeded

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 input().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: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

import sys
import os
import math

n, q = map(int, input().split())
values = [2**31 - 1] * n

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

    # update
    if com == 0:
        values[x] = y

    # find
    else:
        print(min(values[x:y+1]))

Submission status: Time Limit Exceeded

Solution code:
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, input().split())
    Av = [0 for _ in range(n)]
    Ak = [-1 for _ in range(n)]
    ans = []
    for _ in range(q):
        cmd, x, y = map(int, input().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: Time Limit Exceeded

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.readline().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.readline().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: Time Limit Exceeded

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 -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.readline().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.readline().split())
        if cmd == 0:
            updt(Av, Ak, x, y)
        else:
            ans.append(fnd(Av, Ak, x, y))
    for an in ans:
        if an == -1:
            print(2**31 -1, sep="\n")
        else:
            print(an, sep="\n")



if __name__ == "__main__":
    rmq()

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int, input().split())
A = [float("inf")] * 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 == float("inf"): a = "2147483647"
  else: a = str(a)
  print(a)

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
l=[(2**31)-1 for i in range(n)]
for i in range(q):
    a,b,c=map(int,input().split())
    if a == 0:
        l[b]=c
    elif a == 1:
        print(min(l[b:c+1]))

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
l=[(2**31)-1 for i in range(n)]
for _ in range(q):
    a,b,c=map(int,input().split())
    if a == 0:
        l[b]=c
    elif a == 1:
        print(min(l[b:c+1]))

Submission status: Time Limit Exceeded

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


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


def main() :
    n, q = [int(i) for i in input().split()]
    a = [2**31 - 1]*n
    com = []
    x = []
    y= []
    for _ in range(q) :
        tmp = list(map(int, input().split()))
        com.append(tmp[0])
        x.append(tmp[1])
        y.append(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: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
	n, q = input().split()
	n, q = int(n), int(q)
	ini = 2 ** 31 - 1
	lists = [ini for i in range(n)]
	for i in range(q):
		com, x, y = input().split()
		com, x, y = int(com), int(x), int(y)

		if com:
			print(min(lists[x:y + 1]))
		else:
			lists[x] = y

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-

# AOJ: Range Query RMQ
import sys

n, q = map(int, sys.stdin.readline().split())
A = [2**31-1 for i in range(n)]
for i in range(q):
    cmd, x, y = map(int, sys.stdin.readline().split())
    if cmd == 0:
        A[x] = y
    elif cmd == 1:
        print(min(A[x:y+1]))

Submission status: Time Limit Exceeded

Solution code:
import math

INIT_VAL = pow(2, 31)-1

class SegmentTree():
    def __init__(self, n):
        self.n = n
        self.height = math.ceil(math.log2(n))
        self.nodes = [INIT_VAL for i in range(pow(2, self.height+1)-1)]
        self.leaf_start = pow(2, self.height)-1

    def update(self, i, x):
        pntr = self.leaf_start + i
        self.nodes[pntr] = x
        while True:
            pntr = (pntr-1)//2
            l, r = pntr*2 + 1, pntr*2 + 2
            self.nodes[pntr] = min(self.nodes[l], self.nodes[r])
            if pntr == 0: break

    def __query(self, s, t, k, l, r):
        if t - s <= 0: return INIT_VAL
        if r <= s or t <= l: return INIT_VAL
        if l == s and t == r: return self.nodes[k]
        else:
            m = (l+r)//2
            vl = self.__query(s, m, k*2+1, l, m)
            vr = self.__query(m, t, k*2+2, m, r)
            return min(vl, vr)

    def find(self, s, t):
        return self.__query(s, t+1, 0, 0, pow(2, self.height))

n, q = list(map(int, input().split(' ')))
st = SegmentTree(n)
for i in range(q):
    com, x, y = list(map(int, input().split(' ')))
    if com == 0:
        st.update(x, y)
    elif com == 1:
        print(st.find(x, y))

Submission status: Time Limit Exceeded

Solution code:
class A():
	def __init__(self, n):
		self.ary = [2**31-1 for i in range(n_q[0])]
		
	def myfind(self, x, y):
		if x != y:
			print min(self.ary[x:y+1])
		else:
			print self.ary[x]
		
	def myupdate(self, x, y):
		self.ary[x] = y
		
	
n_q = map(int, raw_input().split())

obj		= A(n_q[0])
dataset	= [map(int, raw_input().split()) for i in range(n_q[1])] 

for data in dataset:
	method_set = [obj.myupdate, obj.myfind]
	method_set[data[0]](data[1], data[2])

Submission status: Time Limit Exceeded

Solution code:
def myfind(x, y):
	if x != y:
		print min(A[x:y+1])
	else:
		print A[x]
		
def myupdate(x, y):
	A[x] = y
	
	
n_and_q = map(int, raw_input().split())
n = n_and_q[0]
q = n_and_q[1]

A = [2**31 -1 for i in range(n)]
dataset = [map(int, raw_input().split()) for i in range(q)]

func_set = (myupdate, myfind)
for data in dataset:
	func_set[data[0]](data[1], data[2])

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin


def main(init=int(2**31-1)):
    n, q = (int(s) for s in stdin.readline().split())

    a = [init] * n

    for _ in range(q):
        com, x, y = (int(s) for s in stdin.readline().split())
        if com:
            print(min(a[x:y+1]))
        else:
            a[x] = y


main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin


def main(init=int(2**31-1)):
    n, q = (int(s) for s in stdin.readline().split())

    a = [init] * n
    px = py = init

    for _ in range(q):
        com, x, y = (int(s) for s in stdin.readline().split())
        if com:
            if x != px or py != y:
                m = min(a[x:y+1])
                px = x
                py = y
            print(m)
        else:
            a[x] = y
            px = py = init


main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin


def main(init=int(2**31-1)):
    n, q = (int(s) for s in stdin.readline().split())

    a = [init] * n
    b = {}

    for _ in range(q):
        com, x, y = (int(s) for s in stdin.readline().split())
        if com:
            try:
                m = b[(x, y)]
            except KeyError:
                m = min(a[x:y+1])
                b[(x, y)] = m
            print(m)
        else:
            a[x] = y
            for i, j in b.keys():
                if i <= x <= j:
                    del b[(i, j)]


main()