# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
676503 | penguin133 | Deda (COCI17_deda) | C++17 | 176 ms | 29840 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
#define pi pair<int, int>
#define pii pair<int, pair<int, int> >
#define fi first
#define se second
int n,q;
struct node{
int s,e,m,val;
node *l, *r;
node(int _s, int _e){
s = _s, e = _e, m = (s + e)/2, val = 2e9;
if(s != e)l = new node(s, m), r= new node(m+1, e);
}
void upd(int p, int v){
if(s == e)val = v;
else{
if(p <= m)l->upd(p, v);
else r->upd(p, v);
val = min(l->val, r->val);
}
}
int query(int a, int b){
if(a == s && b == e)return val;
else if(b <= m)return l->query(a, b);
else if(a > m)return r->query(a, b);
else return min(l->query(a, m), r->query(m+1, b));
}
int find(int a, int v){
if(e < a)return -1;
if(s == e)return (val > v ? -1 : s);
int x = -1;
if(l->val <= v)x = l->find(a, v);
if(x != -1)return x;
else return r->find(a, v);
}
}*root;
void solve(){
cin >> n >> q;
root = new node(1, n);
while(q--){
char x;cin >> x;
if(x == 'M'){
int a,b;cin >>a >> b;
root->upd(b, a);
}
else{
int a, b;cin >>a >> b;
cout << root->find(b, a) << '\n';
}
}
}
main(){
ios::sync_with_stdio(0);cin.tie(0);
int t = 1;
//cin >> t;
while(t--){
solve();
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |