Submission #445984

# Submission time Handle Problem Language Result Execution time Memory
445984 2021-07-20T10:34:30 Z nickmet2004 Deda (COCI17_deda) C++11
0 / 140
122 ms 4292 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);
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 3404 KB Output isn't correct
2 Incorrect 2 ms 3404 KB Output isn't correct
3 Incorrect 4 ms 3468 KB Output isn't correct
4 Incorrect 115 ms 4292 KB Output isn't correct
5 Incorrect 112 ms 3988 KB Output isn't correct
6 Incorrect 116 ms 4164 KB Output isn't correct
7 Incorrect 122 ms 4188 KB Output isn't correct