Submission details
Task:Dynamic Range Minimum Queries
Sender:aalto26dh_006
Submission time:2026-09-21 13:33:49 +0300
Language:Python3 (PyPy3)
Status:READY
Result:
Test results
testverdicttime
#10.07 sdetails
#20.12 sdetails

Code

import math

def main():
    n,q = [int(x) for x in input().split()]
    values = [int(x) for x in input().split()]

    N = math.ceil(math.sqrt(n))

    tree = [float('inf')] * N * 2
    tree.append(values)

    for i in range(N-1, 2, -1):
        if i >= N:
            tree[i] = values[i-N]
        else:
            tree[i] = min(tree[i*2], tree[i*2+1])


    def update(k, x):
        k += N
        tree[k] = x
        for i in range(k/2,2,k/2):
            tree[i] = min(tree[k*2], tree[k*2+1])

    def query(a,b):
        a += N
        b += N
        s = float('inf')

        while (a <= b):
            if a % 2 == 1:
                s = min(s, tree[a+1])
            if b % 2 == 0:
                s = min(s, tree[b+1])
            a /= 2
            b /= 2



    

    for _ in range(q):
        action = [int(x) for x in input().split()]

        if action[0] == 1:
            update(action[1]-1, action[2])
        else:
            print(query(action[1]-1, action[2]-1))

main()

Test details

Test 1

Verdict:

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
(empty)

Error:
Traceback (most recent call last):
  File "/box/input/code.py", line 50, in <module>
    main()
  File "/box/input/code.py", line 48, in main
    print(query(action[1]-1, action[2]-1))
  File "/box/input/code.py", line 34, in query
    s = min(s, tree[b+1])
TypeError: list indices must be integers or slices, not float

Test 2

Verdict:

input
200000 200000
398739055 65343131 699208332 3...

correct output
28609
129890
20378
20378
311522
...

user output
(empty)

Error:
Traceback (most recent call last):
  File "/box/input/code.py", line 50, in <module>
    main()
  File "/box/input/code.py", line 46, in main
    update(action[1]-1, action[2])
  File "/box/input/code.py", line 21, in update
    tree[k] = x
IndexError: list index out of range