# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
445805 | nickmet2004 | Deda (COCI17_deda) | C++11 | 434 ms | 7868 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 = 2e5 + 5;
int n , q , a[N];
int T[1<<20] , S , A;
char B;
void upd(int id , int l = 0 , int r = n - 1 , int pos= 0){
if(id < l || id > r) return;
if(l == r){T[pos] = S; return;}
int mid = (l + r) >>1;
upd(id ,l , mid ,pos * 2 + 1);
upd(id ,mid + 1 , r , pos * 2 + 2);
T[pos] = min(T[pos * 2 + 1] ,T[pos * 2 + 2]);
}
int f(int L , int R , int l = 0 , int r = n - 1 , int pos = 0){
if(R < l || r < L)return -1;
if(L <= l && r <= R){
if(T[pos] > S)return -1;
while(l < r){
int mid = (l + r) >>1;
if(T[pos * 2 + 1] <= S) r= mid , pos = pos * 2 + 1;
else pos = pos * 2 + 2 , l = mid+ 1;
}return l;
}
int mid = (l + r) >> 1;
int k = f(L , R , l , mid , pos * 2 + 1);
if(k != -1)return k;
return f(L , R , mid + 1 , r , pos * 2 + 2);
}
int main (){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> q;
for(int i = 0; i < 4 * N; ++i) T[i] = 2e9;
while(q--){
cin >> B >> S >> A; --A;
if(B == 'M') upd(A);
else {
int x =f(A , n - 1);
if(x != -1) cout << x + 1 << endl;
else cout << x << endl;
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |