# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
380356 | ritul_kr_singh | Deda (COCI17_deda) | C++17 | 137 ms | 8940 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 sp << ' ' <<
#define nl << '\n'
struct segtree{
int sz = 1, lim; const int ID = 1e10;
vector<int> a;
segtree(int n){
while(sz < n) sz *= 2;
lim = n;
a.assign(2*sz, ID);
}
void update(int i, int val, int x, int lx, int rx){
if(rx-lx==1) return void(a[x] = val);
int mx = (lx+rx)/2;
if(i<mx) update(i, val, 2*x+1, lx, mx);
else update(i, val, 2*x+2, mx, rx);
a[x] = min(a[2*x+1], a[2*x+2]);
}
void update(int i, int val){ update(i, val, 0, 0, sz); }
int get(int l, int val, int x, int lx, int rx){
if(rx<=l) return ID;
if(rx-lx==1) return (lx>=l ? lx : ID);
int mx = (lx+rx)/2;
int res = ID;
if(a[2*x+1]<=val) res = get(l, val, 2*x+1, lx, mx);
if(res==ID and a[2*x+2]<=val) res = get(l, val, 2*x+2, mx, rx);
return res;
}
int get(int l, int val){
int res = get(l, val, 0, 0, sz);
return (res==ID or res>=lim? -1 : res+1);
}
};
signed main(){
ios_base::sync_with_stdio(false); cin.tie(nullptr);
int n, q; cin >> n >> q;
segtree st(n);
char c;
int x, y;
while(q--){
cin >> c >> x >> y;
if(c=='M') st.update(y-1, x);
else cout << st.get(y-1, x) nl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |