-
Notifications
You must be signed in to change notification settings - Fork 0
/
BOJ_14438.py
52 lines (40 loc) · 1.24 KB
/
BOJ_14438.py
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import sys
from math import log2, ceil
INF = sys.maxsize
input = sys.stdin.readline
def init(node, start, end):
if start == end:
tree[node] = l[start]
return tree[node]
mid = (start + end) // 2
tree[node] = min(init(node*2, start, mid), init(node*2+1, mid+1, end))
return tree[node]
def query(node, start, end, left, right):
if left > end or right < start:
return INF
if left <= start and end <= right:
return tree[node]
mid = (start + end) // 2
return min(query(node*2, start, mid, left, right), query(node*2+1, mid+1, end, left, right))
def update(node, start, end, index, to):
if index < start or end < index:
return tree[node]
if start == end:
tree[node] = to
return tree[node]
mid = (start + end) // 2
tree[node] = min(update(node*2, start, mid, index, to), update(node*2+1, mid+1, end, index, to))
return tree[node]
n = int(input())
l = list(map(int, input().split()))
m = int(input())
height = ceil(log2(n))
size = 2 ** (height + 1)
tree = [INF for _ in range(size)]
init(1, 0, n-1)
for _ in range(m):
q, i, j = map(int, input().split())
if q == 1:
update(1, 0, n-1, i-1, j)
else:
print(query(1, 0, n-1, i-1, j-1))