Submission #445987

# Submission time Handle Problem Language Result Execution time Memory
445987 2021-07-20T10:36:59 Z nickmet2004 Deda (COCI17_deda) C++11
140 / 140
425 ms 4464 KB
#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 -2;
    if(L <= l && r <= R){
        if(T[pos] > S)return -2;
        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 != -2)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 cout << f(A , n - 1)+1<<endl;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3404 KB Output is correct
2 Correct 3 ms 3404 KB Output is correct
3 Correct 10 ms 3404 KB Output is correct
4 Correct 425 ms 4424 KB Output is correct
5 Correct 320 ms 4128 KB Output is correct
6 Correct 346 ms 4224 KB Output is correct
7 Correct 375 ms 4464 KB Output is correct