# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
79821 | pzdba | Deda (COCI17_deda) | C++14 | 1080 ms | 17040 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 N = 200000;
int st[4*N+5];
void update(int n, int s, int e, int idx, int v){
if(s == e){
st[n] = v;
}
else{
int mid = (s+e)/2;
if(idx <= mid) update(n+n, s, mid, idx, v);
else update(n+n+1, mid+1, e, idx, v);
st[n] = min(st[n+n], st[n+n+1]);
}
}
int query(int n, int s, int e, int l, int r){
if(s > r || l > e) return 2e9;
if(l <= s && e <= r) return st[n];
int mid = (s+e)/2;
int q1 = query(n+n, s, mid, l, r);
int q2 = query(n+n+1, mid+1, e, l, r);
return min(q1, q2);
}
int main(){
int n, q;
scanf("%d%d", &n, &q);
for(int i=1;i<=n;i++) update(1, 1, n, i, 2e9);
for(int i=1;i<=q;i++){
char s[2];
int x, a;
scanf("%s%d%d", s, &x, &a);
if(s[0] == 'M'){
update(1, 1, n, a, x);
}
else{
int y = x, b = a;
int lo = b, hi = n, ans = -1;
while(lo <= hi){
int mid = (lo+hi)/2;
if(query(1, 1, n, b, mid) <= y) ans = mid, hi = mid-1;
else lo = mid+1;
}
printf("%d\n", ans);
}
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |