Task: | Dynamic Range Minimum Queries |
Sender: | esya_rae |
Submission time: | 2024-09-23 16:13:42 +0300 |
Language: | Python3 (PyPy3) |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.04 s | details |
#2 | ACCEPTED | 0.87 s | details |
Code
import math def build_tree(i): global x, tree, k, n if i >= k + n: return math.inf if i >= k: tree[i] = x[i - k] return tree[i] tree[i] = min(build_tree(2 * i), build_tree(2 * i + 1)) return tree[i] def update(i, u): global tree, k tree[i] = u while i > 1: i //= 2 tree[i] = min(tree[2 * i], tree[2 * i + 1]) def answer(a, b): global tree, k res = math.inf a += k b += k while a <= b: if a % 2 == 1: res = min(res, tree[a]) a += 1 if b % 2 == 0: res = min(res, tree[b]) b -= 1 a //= 2 b //= 2 return res n, q = map(int, input().split()) x = list(map(int, input().split())) k = 2 ** math.ceil(math.log(n, 2)) tree = [math.inf] * (2 * k) build_tree(1) for i in range(q): a, j, u = map(int, input().split()) if a == 1: update(j - 1 + k, u) else: print(answer(j - 1, u - 1))
Test details
Test 1
Verdict: ACCEPTED
input |
---|
8 80 7 6 4 6 2 9 4 8 2 1 1 2 1 2 2 1 3 ... |
correct output |
---|
7 6 4 4 2 ... |
user output |
---|
7 6 4 4 2 ... Truncated |
Test 2
Verdict: ACCEPTED
input |
---|
200000 200000 398739055 65343131 699208332 3... |
correct output |
---|
28609 129890 20378 20378 311522 ... |
user output |
---|
28609 129890 20378 20378 311522 ... Truncated |