Pagini recente » Cod sursa (job #408517) | Cod sursa (job #678142) | Cod sursa (job #1419833) | Cod sursa (job #2246347) | Cod sursa (job #2899695)
#include <iostream>
#include <fstream>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
using namespace std;
ifstream f("zeap.in");
ofstream g("zeap.out");
set<int>z;
priority_queue<pair<int,pair<int,int>>, vector<pair<int,pair<int,int>>>, greater<pair<int,pair<int,int>>> > d;
int main()
{
int x;
char c;
char s[5];
while(f>>s)
{
c = s[0];
if(c == 'I')
{
f>>x;
z.insert(x);
auto i = z.find(x);
if(i!=z.begin())
{
i--;
d.push({x-*i,{*i,x}});
i++;
}
if(++i!=z.end())
{
d.push({*i-x,{*i,x}});
}
}
if(c == 'S')
{
f >> x;
if(z.find(x) != z.end())
{
auto i = z.find(x);
auto j = ++i;
i--;
auto k = --i;
d.push({*j - *k, {*j, *k}});
z.erase(x);
}
else
{
g << -1 << endl;
}
}
if(c == 'C')
{
f >> x;
if(z.find(x) == z.end())
g << 0 << endl;
else
g << 1 << endl;
}
if(c == 'M')
{
c = s[2];
if(c == 'N')
{
if(z.size() < 2)
g << -1 << endl;
else
{
while(!d.empty() && (z.find(d.top().second.first) == z.end() || z.find(d.top().second.second) == z.end()))
{
d.pop();
}
g << d.top().first << endl;
}
}
if(c == 'X')
{
if(z.size() < 2)
g << -1 << endl;
else
{
g << *(--z.end()) - *(z.begin()) << endl;
}
}
}
}
}