# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
84021 | sams | Deda (COCI17_deda) | C++14 | 388 ms | 4672 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;
const int MAXN=2e5+10, INF=0x3f3f3f3f;
int n, q, seg[4*MAXN];
void upd(int i, int x, int u=1, int l=1, int r=n){
if(l==r){
seg[u]=x;
return;
}
int mid=(l+r)/2;
if(i<=mid) upd(i, x, 2*u, l, mid);
else upd(i, x, 2*u+1, mid+1, r);
seg[u]=min(seg[2*u], seg[2*u+1]);
}
int search_seg(int b, int x, int u=1, int l=1, int r=n){
if(seg[u]>x) return INF;
if(b>r) return INF;
if(l==r) return l;
int mid=(l+r)/2;
if(l<b) return min(search_seg(b, x, 2*u, l, mid), search_seg(b, x, 2*u+1, mid+1, r));
if(seg[2*u]<=x) return search_seg(b, x, 2*u, l, mid);
return search_seg(b, x, 2*u+1, mid+1, r);
}
int main(){
scanf("%d%d", &n, &q);
memset(seg, INF, sizeof seg);
for(int i=0;i<q;++i){
char c;
int x, a;
scanf(" %c %d %d", &c, &x, &a);
if(c=='M'){
upd(a, x);
}else{
int k=search_seg(a, x);
if(k>=INF) printf("-1\n");
else printf("%d\n", k);
}
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |