# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
306348 | syy | Deda (COCI17_deda) | C++17 | 585 ms | 26496 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair <int, int> pi; //Station, child
struct node { // Creates a struct for the node of a seg tree
int s, e, m;
pi v; // start, end, middle, rangemin value
node *l, *r; // pointer to left, right subnodes
node(int _s, int _e) { //Constructor to create nodes l and r
s = _s; e = _e; m = (s+e)/2; // initialize variables
v.second = INT_MAX;
v.first = INT_MAX;
if (s!=e) { // is not a leaf node
l = new node(s, m); // create child nodes
r = new node(m+1, e);
}
}
void up(int x, int nv) { //update position x to nv (new value)
if (s==e) { //if node is a leaf, just modify v.
v = pi(nv, x);
return;
}
if (x>m) r->up(x, nv); //update right subtree if update is in right subtree
if (x<=m) l->up(x, nv); //update left subtree if update is in left subtree
v = min(l->v, r->v); //Modify the value of v after updating children
}
pi rmq(int x, int y) { //range min query from position x, y
if (s==x && e==y) return v; //return range min if query range corresponds
if (x>m) return r->rmq(x, y); //query right tree if range only lies there
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |