Task: | Dynamic Range Minimum Queries |
Sender: | HFalke |
Submission time: | 2024-09-23 19:48:56 +0300 |
Language: | C++ (C++17) |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.00 s | details |
#2 | ACCEPTED | 0.12 s | details |
Code
#include <bits/stdc++.h> using namespace std; //Definitions for quicker writing #define REP(i,c,d) for (int i = c; i < d; i++) //Typedefs for quicker writing typedef long long ll; typedef vector<int> vi; typedef pair<int,int> pi; int main() { //IO optimization ios::sync_with_stdio(0); cin.tie(0); //Input definition int n; int q; cin >> n >> q; //Define segment tree ll seg[2*n]; seg[0] = -1; //Read in values REP(i,0,n){ cin >> seg[i+n]; } //Build segmentation tree for(int i=n-1;i>0;i--){ seg[i] = min(seg[2*i], seg[(2*i)+1]); } //Build helper variables int type; ll a; ll b; ll cur; vector<ll> res; //Main loop //Read a query, disect which type it is //and then perform the according action REP(i,0,q){ //Read in query cin >> type; cin >> a; cin >> b; //If update query if(type==1){ cur = n+a-1; seg[cur] = b; cur /= 2; while(cur >= 1){ seg[cur] = min(seg[2*cur], seg[2 * cur + 1]); cur /= 2; } } //If min query else if(type==2){ a += n-1; b += n-1; cur = 10000000001; while(a <= b){ if(a%2 == 1){ cur = min(cur, seg[a++]); } if(b%2 == 0){ cur = min(cur, seg[b--]); } a /= 2; b /= 2; } res.push_back(cur); } } //Write out for(auto v: res){ cout << v << "\n"; } //Return 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 ... Truncated |
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 ... Truncated |