Cod sursa(job #1194180)
Utilizator | Data | 3 iunie 2014 02:34:42 | |
---|---|---|---|
Problema | Zeap | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 3.61 kb |
#include<cstdio>
#include<cstring>
#include<fstream>
#include<set>
using namespace std;
ofstream fo("zeap.out");
const int inf = (1LL<<31)-1;
pair <set<int>::iterator,bool> aux;
multiset <int> m_set;
set <int>::iterator it;
set <int> s;
int i,x,a,b;
char c,linie[14];
int lung;
int main(){
FILE *ok_f;
ok_f=freopen("zeap.in","r",stdin);
s.insert(0);
s.insert(inf);
while(gets(linie)){
lung=strlen(linie);
if(linie[0]=='M') c=linie[2];
else{
c=linie[0]; x=0;
for(i=2;i<lung;i++) x=x*10+linie[i]-'0';
}
if(c=='I')
{
aux=s.insert(x);
if(aux.second){
it=aux.first;
it--;
a=*it;
it++;
it++;
b=*it;
if(a>0) m_set.insert(x-a);
if(b<inf) m_set.insert(b-x);
if(a>0 && b<inf) m_set.insert(b-a);
}
continue;
}
else if(c=='S')
{
it=s.find(x);
if(it!=s.end()){
it--;
a=*it;
it++;
it++;
b=*it;
it--;
if(a>0) m_set.erase(m_set.find(x-a));
if(b<inf) m_set.erase(m_set.find(b-x));
if(a>0 && b<inf) m_set.insert(b-a);
s.erase(it);
}
else fo<<"-1\n";
continue;
}
else if(c=='C'){
if(s.find(x)!=s.end()) fo<<"1\n";
else fo<<"0\n";
continue;
}
else{
if(c=='X')
{
if(s.size()<=3) fo<<"-1\n";
else{
it=s.end();
it--;
it--;
a=*it;
it=s.begin();
it++;
b=*it;
fo<<a-b<<"\n";
}
continue;
}
else if(c=='N')
{
if(s.size()<=3) fo<<"-1\n";
else fo<<*(m_set.begin())<<"\n";
}
continue;
}
}
fclose(stdin);
fo.close();
return 0;
}