This commit is contained in:
Zengtudor 2024-10-21 11:21:10 +08:00
parent 2f6eb0bc61
commit 93c7ee4776
2 changed files with 100 additions and 0 deletions

View File

@ -0,0 +1,48 @@
#include <algorithm>
#include <cstdlib>
#include <iomanip>
#include <ios>
#include <iostream>
#include <limits>
#include <set>
typedef long long ll;
const ll max_n = 1e5+5;
ll n, q, input,now;
char c;
std::set<ll> pos;
#define NV(v)#v<<" : "<<(v)
int main(){
freopen("secret.in", "r", stdin);
freopen("secret.out", "w", stdout);
std::cin>>n>>q;
for(ll _{0};_<n;_++){
std::cin>>input;
pos.insert(input);
}
for(ll _{0};_<q;_++){
std::cin>>c>>now;
if(c=='+'){
pos.insert(now);
}else if(c=='-'){
pos.erase(now);
}else{
double ans = std::numeric_limits<decltype(ans)>::max();
const auto it_right {pos.upper_bound(now)};
if ( it_right != pos.end()){
ans = std::min(ans, (double)std::max(*pos.rbegin()-now, *it_right - *pos.begin()) / (double)2.0 );
}
auto it_left {pos.find(now)};
if(it_left!=pos.begin()){
--it_left;
ans = std::min(ans, (double)std::max(*pos.rbegin() - *it_left, now - *pos.begin()) / (double)2.0 );
}
std::cout<<std::fixed<<std::setprecision(2)<<ans<<'\n';
}
}
}

View File

@ -0,0 +1,52 @@
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
set<ll>s;
set<ll>::iterator it;
int main()
{
freopen("secret.in","r",stdin);
freopen("secret.out","w",stdout);
ll n,q,x,i;
double ans;
char pd;
cin>>n>>q;
for(i=1;i<=n;i++)
{
cin>>x;
s.insert(x);
}
for(i=1;i<=q;i++)
{
cin>>pd>>x;
if(pd=='+')
{
s.insert(x);
}
if(pd=='-')
{
s.erase(x);
}
if(pd=='?')
{
ans=0x7f7f7f7f;
it=s.upper_bound(x);
if(it!=s.end())
{
ans=min(ans,max(*it-*s.begin(),*(--s.end())-x)/2.0);
}
it=s.find(x);
if(it!=s.begin())
{
it=prev(it);
ans=min(ans,max(x-*s.begin(),*(--s.end())-*it)/2.0);
}
printf("%.2lf\n",ans);
}
}
fclose(stdin);
fclose(stdout);
return 0;
}