From 93c7ee477617c5d899b16dcc4db454fa90baf98a Mon Sep 17 00:00:00 2001 From: Zengtudor Date: Mon, 21 Oct 2024 11:21:10 +0800 Subject: [PATCH] update --- src/20241019/secret/secret_after.cpp | 48 +++++++++++++++++++++++++ src/20241019/secret/secret_web.cpp | 52 ++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 src/20241019/secret/secret_after.cpp create mode 100644 src/20241019/secret/secret_web.cpp diff --git a/src/20241019/secret/secret_after.cpp b/src/20241019/secret/secret_after.cpp new file mode 100644 index 0000000..b3cdcbb --- /dev/null +++ b/src/20241019/secret/secret_after.cpp @@ -0,0 +1,48 @@ + +#include +#include +#include +#include +#include +#include +#include +typedef long long ll; + +const ll max_n = 1e5+5; +ll n, q, input,now; +char c; +std::set 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};_>input; + pos.insert(input); + } + for(ll _{0};_>c>>now; + + if(c=='+'){ + pos.insert(now); + }else if(c=='-'){ + pos.erase(now); + }else{ + double ans = std::numeric_limits::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< +using namespace std; + +using ll = long long; + +sets; +set::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; +} \ No newline at end of file