# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
954255 | vjudge1 | Deda (COCI17_deda) | C++17 | 101 ms | 7848 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 ishowspeed ios::sync_with_stdio(0),cin.tie(0);
#define int long long
#define MXN 200055
#define cl(x) (x<<1)
#define cr(x) (x<<1)+1
int seg[MXN*4+5],arr[MXN];
int searchb = 1e18;
int ansl = 1e18;
int query(int id,int l,int r,int sl,int sr){
if(sl<=l&&r<=sr) {
if(seg[id] > searchb) return seg[id];
else{
if(l == r) {
ansl = min(ansl,l);
return seg[id];
}
}
}
int mid=(l+r)>>1,res=1e18;
if(sl<=mid){
int x = query(cl(id),l,mid,sl,sr);
res = min(res,x);
if(x <= searchb) return res;
}
if(mid<sr){
int x = query(cr(id),mid+1,r,sl,sr);
res = min(res,x);
}
return res;
}
void pull(int id){
seg[id] = min(seg[cl(id)] , seg[cr(id)]);
}
void update(int id,int l,int r,int x,int v){
if(l==r){
seg[id] = v;
return;
}
int mid=(l+r)>>1;
if(x<=mid){
update(cl(id),l,mid,x,v);
}
if(mid<x){
update(cr(id),mid+1,r,x,v);
}
pull(id);
}
void build(int id,int l,int r){
if(l==r){
seg[id]=arr[l];
return;
}
int mid=(l+r)>>1;
build(cl(id),l,mid);
build(cr(id),mid+1,r);
pull(id);
}
signed main(){
ishowspeed
int n,q,x,L,R;
cin >> n >> q;
L = 1;
R = n;
for(int i = 1;i <= n;i++) arr[i] = 1e18;
build(1,L,R);
char o;
int a,b;
while(q--){
cin >> o >> a >> b;
if(o == 'M') update(1,L,R,b,a);
else {
searchb = a;
ansl = 1e18;
int rs = query(1,1,R,b,R);
if(rs <= searchb) cout << ansl << '\n';
else cout << "-1\n";
}
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |