Submission details
Task:Dynamic Range Minimum Queries
Sender:aalto26dh_039
Submission time:2026-09-19 23:10:41 +0300
Language:C++ (C++20)
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.47 sdetails

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:53:23: warning: comparison of integer expressions of different signedness: 'int' and 'uint32_t' {aka 'unsigned int'} [-Wsign-compare]
   53 |     for (int i = 0; i < n; ++i) {
      |                     ~~^~~
input/code.cpp:62:23: warning: comparison of integer expressions of different signedness: 'int' and 'uint32_t' {aka 'unsigned int'} [-Wsign-compare]
   62 |     for (int i = 0; i < q; ++i) {
      |                     ~~^~~

Code

#include <iostream>
#include <vector>
#include <numeric>
#include <cstdint>

uint32_t find_power(uint32_t n) {
    n--;
    n |= n >> 1;
    n |= n >> 2;
    n |= n >> 4;
    n |= n >> 8;
    n |= n >> 16;
    n++;
    return n;
}

uint32_t p_n;

uint64_t build_segment_tree(std::vector<uint64_t> &tree, uint64_t idx) {
    if (tree[idx] == UINT64_MAX && idx < tree.size()) {
        tree[idx] = std::min(build_segment_tree(tree, 2*idx), build_segment_tree(tree, 2*idx+1));
    }
    return tree[idx];
}

void update(auto &tree, uint64_t idx, uint64_t value) {
    idx += p_n;
    tree[idx] = value;
    for (idx /= 2; idx >= 1; idx /= 2) {
        tree[idx] = std::min(tree[2*idx], tree[2*idx+1]);
    }
}

uint64_t get_min(auto &tree, uint64_t a, uint64_t b) {
    a += p_n;
    b += p_n;
    uint64_t min = UINT64_MAX;
    while (a <= b) {
        if (a%2 == 1) min = std::min(tree[a++], min);
        if (b%2 == 0) min = std::min(tree[b--], min);
        a /= 2;
        b /= 2;
    }
    return min;
}

int main() {
    uint32_t n, q;
    std::cin >> n >> q;
    p_n = find_power(n);

    std::vector<uint64_t> segment_tree(p_n*2, UINT64_MAX);
    for (int i = 0; i < n; ++i) {
        uint64_t e;
        std::cin >> e;
        segment_tree[p_n+i] = e; 
    }

    build_segment_tree(segment_tree, 1);
    std::vector<uint64_t> outputs;

    for (int i = 0; i < q; ++i) {
        uint32_t t, a, b;
        std::cin >> t >> a >> b;

        if (t == 1) update(segment_tree, a-1, b);
        else outputs.push_back(get_min(segment_tree, a-1, b-1));
    }

    for (auto output : outputs) {
        std::cout << output << std::endl;
    }
}

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