| Task: | Dynamic Range Minimum Queries |
| Sender: | aalto26dh_050 |
| Submission time: | 2026-09-18 00:21:58 +0300 |
| Language: | C++ (C++20) |
| Status: | READY |
| Result: | ACCEPTED |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.00 s | details |
| #2 | ACCEPTED | 0.48 s | details |
Code
#include <iostream>
#include <vector>
#include <cmath>
#include <bits/stdc++.h>
using namespace std;
int min_in_range(int a, int b, vector<int> & tree)
{
int n = tree.size() / 2;
a += n; b += n;
int s = pow(10, 9);
while (a <= b)
{
if (a%2 == 1) s = min(tree[a++], s);
if (b%2 == 0) s = min(tree[b--], s);
a /= 2; b /= 2;
}
return s;
}
void add(int k, int x, vector<int> & tree)
{
int n = tree.size() / 2;
k += n;
tree[k] = x;
for (k /= 2; k >= 1; k /= 2)
{
tree[k] = min(tree[2*k], tree[2*k+1]);
}
}
int main()
{
int n_values, n_queries;
cin >> n_values >> n_queries;
int base_array_size = pow(2, ceil(log2(n_values)));
int full_array_size = 2 * base_array_size;
vector<int> segmented_tree(full_array_size, 1000000000);
for(int i = 0; i < n_values; ++i)
{
int temp;
cin >> temp;
add(i, temp, segmented_tree);
}
for(int i = 0; i < n_queries; ++i)
{
int order, op1, op2;
cin >> order >> op1 >> op2;
if(order == 1)
{
add(op1 - 1, op2, segmented_tree);
}
else
{
cout << min_in_range(op1 - 1, op2 - 1, segmented_tree) << 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 ... |
