Pagini recente » Cod sursa (job #2487631) | Cod sursa (job #2020664) | Cod sursa (job #1369916) | Cod sursa (job #241507) | Cod sursa (job #2899366)
#include <bits/stdc++.h>
using namespace std;
ifstream in("zeap.in");
ofstream out("zeap.out");
priority_queue<pair<int,pair<int,int>>, vector<pair<int,pair<int,int>>>, greater<pair<int,pair<int,int>>> > pq;
set<int> s;
int x;
string op;
char c;
void inserare()
{
in >> x;
s.insert(x);
set<int>::iterator it = s.find(x);
if(it != s.begin())
{
--it;
pq.push({x-*it,{*it, x}});
++it;
}
if(++it != s.end())
{
pq.push({*it -x,{*it, x}});
}
}
void stergere()
{
in >> x;
if(s.find(x) != s.end())
{
set<int>::iterator it = s.find(x);
set<int>::iterator it1 = ++it;
--it;
set<int>::iterator it2 = --it;
//it++;
pq.push({*it1 - *it2, {*it1, *it2}});
s.erase(x);
}
else
out << -1 << '\n';
}
void cautare()
{
in >> x;
if(s.find(x) == s.end())
out << 0 << endl;
else
out << 1 << endl;
}
void minii()
{
if(s.size() <= 1)
out << -1 << endl;
else
{
while(!pq.empty() && (s.find(pq.top().second.first) == s.end() || s.find(pq.top().second.second) == s.end()))
{
pq.pop();
}
out << pq.top().first << endl;
}
}
void maxii()
{
if(s.size() <= 1)
out << -1 << endl;
else
out << *(--s.end()) - *(s.begin()) << endl;
}
int main()
{
while(in >> op)
{
c = op[0];
if(c == 'I')
inserare();
if(c == 'S')
stergere();
if(c == 'C')
cautare();
if(c == 'M')
{
c = op[1];
if(c == 'I')
minii();
if(c == 'A')
maxii();
}
}
return 0;
}