提交时间:2025-06-06 18:56:59

运行 ID: 37959

#include<bits/stdc++.h> #include<bits/extc++.h> #pragma gcc optimize(2) #define up(i,l,r) for(int i=(l);i<=(r);++i) #define down(i,l,r) for(int i=(l);i>=(r);--i) #define pi pair<int,int> #define pdb pair<db,db> #define p1 first #define p2 second #define m_p make_pair #define p_b push_back #define ppc __builtin_popcountll #define ldb long double using namespace std; using namespace __gnu_pbds; typedef long double db; typedef long long ll; typedef unsigned int uint; typedef __int128_t i128; typedef unsigned long long ull; typedef unsigned int uint; const db eps=1e-9; const int maxn=2e5+10,maxq=5e5+10,base=59,mod=998244353; inline ll read(){ ll x=0;short t=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')t=-1;ch=getchar();} while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar(); return x*t; } inline char rd(){ char ch=getchar(); while(ch<=32||ch>=127)ch=getchar(); return ch; } inline int add(int a,int b){if((a+=b)>=mod)a-=mod;return a;} int n,a[maxn],b[maxn]; struct _ { pdb Q[maxn]; db F(pdb a,db i){return -i*a.p1+a.p2;} db Slope(pdb a,pdb b){return (b.p2-a.p2)/(b.p1-a.p1);} int L,R; stack<pair<int,pdb> >S; void init(){ L=n+1,R=n; } void PB(pdb X){ while(L<=R&&Slope(Q[R-1],Q[R])<Slope(Q[R],X))R--; S.push(m_p(R,Q[R]));Q[++R]=X; } void rvk(){ auto it=S.top();S.pop();Q[it.p1]=it.p2; } void PF(pdb X){ while(L<=R&&Slope(X,Q[L])<Slope(Q[L],Q[L+1]))L++; Q[--L]=X; } db ask(db x){ if(L>R)return -1e18; if(L==R)return F(Q[L],x); int l=L,r=R; while(l+1<r){ int mid=l+r>>1; if(Slope(Q[mid],Q[mid+1])>x)l=mid; else r=mid; } return max(F(Q[L],x),F(Q[L+1],x)); } }A,B; db f(db x){ return max(A.ask(x),B.ask(x))*(n-1)+2*x; } int tl[maxn],tr[maxn]; void slv(){ n=read();up(i,0,n-1)a[i]=read();up(i,0,n-1)b[i]=read(); A.init(),B.init(); down(i,n-1,1)tl[i]=A.L,tr[i]=A.R,A.PB(m_p(1.0/i,a[i]*1.0/i)); up(i,0,n-1){ if(i)B.PF(m_p(1.0/i,b[i]*1.0/i)),A.rvk(),A.L=tl[i],A.R=tr[i]; db l=0,r=1e9; while(l+eps<r){ db m1=l+(r-l)/3,m2=r-(r-l)/3; if(f(m1)<f(m2))r=m2; else l=m1; } printf("%.10Lf ",f(l)); } } int main(){ freopen("1.in","r",stdin),freopen("1.out","w",stdout); //int t=read();while(t--)slv(); slv(); cerr<<clock()*1.0/CLOCKS_PER_SEC<<"s\n"; return 0; }{}