Submission details
Task:Dynamic Range Minimum Queries
Sender:aalto26dh_023
Submission time:2026-09-23 15:00:53 +0300
Language:C++ (C++20)
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.49 sdetails

Code

#include <bits/stdc++.h>
using namespace std;

int main() {
    int n, q;
    cin >> n >> q;

    vector<long long> a(n + 1);
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }

    vector<long long> tree(4 * n + 5);

    for (int i = 1; i <= n; ++i) {
        tree[n + i - 1] = a[i];
    }

    for (int i = n - 1; i >= 1; --i) {
        tree[i] = min(tree[2 * i], tree[2 * i + 1]);
    }


    while (q--) {
        int type;
        cin >> type;

        if (type == 1) {
            int k;
            long long u;
            cin >> k >> u;

            int pos = n + k - 1;
            tree[pos] = u;

            for (pos /= 2; pos >= 1; pos /= 2) {
                tree[pos] = min(tree[2 * pos], tree[2 * pos + 1]);
            }
        } else {
            int L, R;
            cin >> L >> R;

            long long ans = LLONG_MAX;

            L += n - 1;
            R += n - 1;

            while (L <= R) {
                if (L % 2 == 1) {
                    ans = min(ans, tree[L]);
                    ++L;
                }
                if (R % 2 == 0) {
                    ans = min(ans, tree[R]);
                    --R;
                }
                L /= 2;
                R /= 2;
            }
            cout << ans << '\n';
        }
    }

    return 0;
}

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
...

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
...