CSES - Aalto Competitive Programming 2024 - wk4 - Homework - Results
Submission details
Task:Dynamic Range Minimum Queries
Sender:Farah
Submission time:2024-09-24 09:47:02 +0300
Language:Python3 (CPython3)
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.02 sdetails
#2--details

Code

import sys

import threading

def main():
    import sys
    import math
    input = sys.stdin.readline

    n, q = map(int, sys.stdin.readline().split())
    x = list(map(int, sys.stdin.readline().split()))
    size = n
    tree = [0] * (2 * size)

    for i in range(n):
        tree[size + i] = x[i]

    for i in range(size - 1, 0, -1):
        tree[i] = min(tree[2 * i], tree[2 * i + 1])

    for _ in range(q):
        while True:
            s = sys.stdin.readline()
            if s.strip():
                break
        parts = list(map(int, s.strip().split()))
        if parts[0] == 1:

            k, u = parts[1], parts[2]
            k -= 1
            i = k + size
            tree[i] = u
            i //= 2
            while i >= 1:
                tree[i] = min(tree[2 * i], tree[2 * i + 1])
                i //= 2
        else:
            a, b = parts[1], parts[2]
            a -= 1
            l = a + size
            r = b + size
            res = float('inf')
            while l < r:
                if l % 2 == 1:
                    res = min(res, tree[l])
                    l += 1
                if r % 2 == 1:
                    r -= 1
                    res = min(res, tree[r])
                l //= 2
                r //= 2
            print(res)

threading.Thread(target=main).start()

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:

input
200000 200000
398739055 65343131 699208332 3...

correct output
28609
129890
20378
20378
311522
...

user output
(empty)