Cod sursa(job #2673456)

Utilizator OvidRata Ovidiu Ovid Data 16 noiembrie 2020 21:25:24
Problema Zeap Scor 60
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.17 kb
#include<bits/stdc++.h>
using namespace std;
#define INIT  ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount
#define int ll

int t, n, m, k, a[300010], q, l, r;

ifstream fin("zeap.in"); ofstream fout("zeap.out");
#define cout fout
#define cin fin

multiset<int> dif;
set<int> st;


int32_t main(){
INIT



string s;
while(cin>>s){
    int x;
    if(s=="I"){
        cin>>x;

        if( (st.size()>0) && (st.find(x)!=st.end()) ){continue;}
        st.insert(x);
        auto it1=st.find(x);
        if(it1!=st.begin()){it1--; dif.insert(x-*it1); it1++;}
        auto it2=st.find(x);
        if(it2!=st.end()){it2++;if(it2!=st.end()){dif.insert(*it2-x);} it2--;}
        if(  (it1!=st.begin()) && (it2!=st.end()) ){
            it1--; it2++;
            if(it2!=st.end()){
            dif.erase(dif.find(*it2-*it1) );}
        }

    }
    if(s=="S"){
        cin>>x;
        if(st.size()==0){
            cout<<"-1\n"; continue;
        }
        if( (st.find(x)==st.end()) ){
            cout<<"-1\n"; continue;
        }
        auto it1=st.find(x);
        if(it1!=st.begin()){it1--; dif.erase(dif.find(x-*it1) ); it1++;}
        auto it2=st.find(x);
        if(it2!=st.end()){it2++;if(it2!=st.end()){dif.erase(dif.find(*it2-x) );} it2--;}
        if(  (it1!=st.begin()) && (it2!=st.end()) ){
            it1--; it2++;
            if(it2!=st.end()){dif.insert(*it2-*it1);}
        }
        st.erase(x);
    }
    if(s=="C"){
            cin>>x;
        cout<<((st.size()>0) && (st.find(x)!=st.end()) )<<"\n";
    }
    if(s=="MIN"){
        if(dif.size()==0){
            cout<<"-1\n";
        }
        else{
            cout<<*dif.begin()<<"\n";
        }
    }
    if(s=="MAX"){
        if(s.size()<2){
            cout<<"-1\n";
        }
        else{
            auto it=st.end(); it--;
            cout<<(*it-*st.begin())<<"\n";
        }
    }

}



return 0;
}