Pagini recente » Cod sursa (job #2174856) | Arhiva de probleme | Cod sursa (job #2505931) | Cod sursa (job #481750) | Cod sursa (job #2899170)
#include <bits/stdc++.h>
#define FILE "zeap"
#define type pair<int,pair<int,int>>
using namespace std;
ifstream fin(FILE".in");
ofstream fout(FILE".out");
priority_queue<type, vector<type>, greater<type> > pq;
set<int> s;
int main(){
char c;
int x;
string st;
while(fin >> st){
c = st[0];
if(c == 'I'){
fin >> 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}});
}
}
if(c == 'S'){
fin >> 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;
pq.push({*it1 - *it2, {*it1, *it2}});
s.erase(x);
}
else{
fout << -1 << '\n';
}
}
if(c == 'C'){
fin >> x;
if(s.find(x) == s.end())
fout << 0 << '\n';
else
fout << 1 << '\n';
}
if(c == 'M'){
c = st[2];
if(c == 'N'){
if(s.size() < 2)
fout << -1 << '\n';
else{
while(!pq.empty() && (s.find(pq.top().second.first) == s.end() || s.find(pq.top().second.second) == s.end())){
pq.pop();
}
fout << pq.top().first << '\n';
}
}
if(c == 'X'){
if(s.size() < 2)
fout << -1 << '\n';
else{
fout << *(--s.end()) - *(s.begin()) << '\n';
}
}
}
}
return 0;
}