| Task: | Dynamic Range Minimum Queries |
| Sender: | aalto26dh_039 |
| Submission time: | 2026-09-19 23:03:22 +0300 |
| Language: | C++ (C++20) |
| Status: | COMPILE ERROR |
Compiler report
input/code.cpp: In function 'void build_segment_tree(auto:16&, uint64_t)':
input/code.cpp:21:53: warning: top-level comma expression in array subscript is deprecated [-Wcomma-subscript]
21 | tree[idx] = std::min(build_segment_tree[tree, 2*idx], build_segment_tree[tree, 2*idx+1]);
| ^
input/code.cpp:21:86: warning: top-level comma expression in array subscript is deprecated [-Wcomma-subscript]
21 | tree[idx] = std::min(build_segment_tree[tree, 2*idx], build_segment_tree[tree, 2*idx+1]);
| ^
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...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;
void build_segment_tree(auto &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, b);
else outputs.push_back(get_min(segment_tree, a, b));
}
for (auto output : outputs) {
std::cout << output << std::endl;
}
}