Pagini recente » Cod sursa (job #2402775) | Cod sursa (job #1812513) | Cod sursa (job #3241845) | Cod sursa (job #1624019) | Cod sursa (job #2899016)
#include <iostream>
#include <fstream>
#include <set>
#include <queue>
using namespace std;
ifstream fin("zeap.in");
ofstream fout("zeap.out");
set<int> zeap;
set<int>::iterator itr;
priority_queue<pair<int, pair<int,int>>> minn;
int main()
{
string citire;
while(fin>>citire)
{
if(citire[0]=='I')
{
int x;
fin>>x;
if(zeap.find(x)==zeap.end())
{
zeap.insert(x);
auto prezent = zeap.find(x);
auto trecut = prezent;
trecut--;
auto viitor = prezent;
viitor++;
if(prezent != zeap.begin())
{
minn.push(make_pair(-abs(x - *trecut), make_pair(*trecut, x)));
}
if(prezent != zeap.end())
{
minn.push(make_pair(-abs(*viitor - x), make_pair(*viitor, x)));
}
}
/*cout << "\nThe set zeap is : \n";
for (itr = zeap.begin(); itr != zeap.end(); itr++) {
cout << *itr << " ";
}*/
}
if(citire[0]=='S')
{
int x;
fin>>x;
if(zeap.find(x)!=zeap.end())
{
auto prezent = zeap.find(x);
auto trecut = prezent;
trecut--;
auto viitor = prezent;
viitor++;
if(prezent!=zeap.begin() && viitor!=zeap.end())
{
minn.push(make_pair(-abs(*viitor - *trecut), make_pair(*trecut,*viitor)));
}
zeap.erase(x);
}
else
{
fout << "-1"<<'\n';
}
}
if(citire[0]=='C')
{
int x;
fin>>x;
if(zeap.find(x) == zeap.end())
{
fout<<0<<'\n';
}
else
{
fout<<1<<'\n';
}
}
if(citire[1]=='A')
{
if(zeap.size()<2)
{
fout << "-1"<<'\n';
}
else
{
auto finall=zeap.end();
finall--;
fout<<*finall - *(zeap.begin())<<'\n';
}
}
if(citire[1]=='I')
{
if(zeap.size()<2)
{
fout << "-1"<<'\n';
}
else
{
while(zeap.find(minn.top().second.first)==zeap.end() || zeap.find(minn.top().second.second) == zeap.end())
{
minn.pop();
}
fout<<-minn.top().first<<'\n';
}
}
}
return 0;
}