Submission #918836

# Submission time Handle Problem Language Result Execution time Memory
918836 2024-01-30T13:50:58 Z noyancanturk Deda (COCI17_deda) C++17
80 / 140
244 ms 65536 KB
#ifndef Local
    #pragma GCC optimize("O3,unroll-loops")
    const int lim=1e5+100;
#else
    const int lim=3e3+100;
#endif
    
#include "bits/stdc++.h"
using namespace std;
    
#define int int64_t
#define pb push_back
    
const int mod=1e9+7;
using pii=pair<int,int>;
    
int P,VAL;
struct node{
    set<int>vals;
    node *lc,*rc;
    node():lc(nullptr),rc(nullptr){}
    void update(int l,int r){
        vals.insert(VAL);
        if(l==r){
            return;
        }
        int mid=(l+r)>>1;
        if(P<=mid){
            if(!lc)lc = new node();
            lc->update(l,mid);
        }else{
            if(!rc)rc = new node();
            rc->update(mid+1,r);
        }
    }
    int query(int l,int r){
        if(r<=P){
            auto p=vals.lower_bound(VAL);
            if(p!=vals.end()){
                return *p;
            }
            return INT_MAX;
        }
        if(P<l){
            return INT_MAX;
        }
        int mid=(l+r)>>1,ans=INT_MAX;
        if(lc)ans=lc->query(l,mid);
        if(rc)ans=min(ans,rc->query(mid+1,r));
        return ans;
    }
};
struct segtree{
    node root;
    void update(int p,int val){
        P=p,VAL=val;
        root.update(1,(int)1e9);
    }
    int query(int p,int val){
        P=p,VAL=val;
        int ans=root.query(1,(int)1e9);
        if(ans^INT_MAX)return ans;
        return -1;
    }
};

inline void solve(){
    int n,q;
    cin>>n>>q;
    segtree st;
    for(int i=0;i<q;i++){
        char ty;
        int p,v;
        cin>>ty>>p>>v;
        if(ty=='M'){
            st.update(p,v);
        }else{
            cout<<st.query(p,v)<<"\n";
        }
    }
}
    
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
#ifdef Local  
    freopen(".in","r",stdin);
    freopen(".out","w",stdout);
#else
    
#endif
    int t=1;
    //cin>>t;
    while (t--)
    {
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 5 ms 2392 KB Output is correct
4 Correct 66 ms 6432 KB Output is correct
5 Runtime error 206 ms 65536 KB Execution killed with signal 9
6 Runtime error 232 ms 65536 KB Execution killed with signal 9
7 Runtime error 244 ms 65536 KB Execution killed with signal 9