Pagini recente » Cod sursa (job #1503476) | Cod sursa (job #941773) | Cod sursa (job #1044743) | Cod sursa (job #2097147) | Cod sursa (job #2751692)
#include <iostream>
#include <fstream>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
using namespace std;
ifstream f("zeap.in");
ofstream g("zeap.out");
char op;
int x;
bool cmp(const pair<int,int> &a,const pair<int,int> &b) //fct pt
{
return a.first - a.second > b.first - b.second;
}
set <int> s;
priority_queue < pair<int,int> , vector<pair<int,int>> , decltype(&cmp) > dife(cmp);
int main()
{
while(f>>op)
{
if(op != 'M')
{
f>>x;
if(op == 'I')
{
auto p = s.find(x);
if(p == s.end())
{
s.insert(x);
p = s.find(x);
if(p != s.begin())
{
auto q=p;
q--;
dife.push(make_pair(*p, *q));
}
auto q=p;
q++;
if(q != s.end())
{
dife.push(make_pair(*q, *p));
}
}
}
else if(op == 'S')
{
auto p = s.find(x);
if(p == s.end())
g<<-1<<'\n';
else
{
auto q=p;
q++;
if(p != s.begin() && q != s.end())
{
p--;
dife.push(make_pair(*q, *p));
}
s.erase(x);
}
}
else
{
if(s.find(x)!=s.end())
g<<"1"<<"\n";
else
g<<"0"<<"\n";
}
}
else
{
f>>op;
f>>op;
if(op == 'X')
{
if(s.size()>=2)
g<< *(s.rbegin()) - *(s.begin())<<'\n';
else
g<<"-1"<<"\n";
}
else
{
if(s.size() >= 2)
{
while(s.find(dife.top().first)==s.end() || s.find(dife.top().second)==s.end())
{dife.pop();}
g<<dife.top().first - dife.top().second<< '\n';
}
else
g<<"-1"<<"\n";
}
}
}
return 0;
}