2019.2.15 t3 平均值

时间:2023-03-10 01:18:09
2019.2.15 t3 平均值

2019.2.15 t3 平均值

2019.2.15 t3 平均值

2019.2.15 t3 平均值

 #include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <cctype>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std; #define res register int
inline int read()
{
int x(),f(); char ch;
while(!isdigit(ch=getchar())) if(ch=='-') f=-;
while(isdigit(ch)) x=x*+ch-'',ch=getchar();
return f*x;
} inline int max(int x,int y){return x>y?x:y;}
inline double max(double x,double y){return x>y?x:y;}
inline int min(int x,int y){return x<y?x:y;} const int N=+;
int a[N],n,k,L,R,t;
int d[N],q[N],q1[N];
double s[N];//差分数组,前缀和数组 inline bool check(double m)
{
int l=,r=; //把i看成右端点(此处取得最大s),找s[i]最小的左端点
double ans(-1e9-);
for(res i= ; i<=n ; i++)
{
if(i-L+<=) continue;
while(l<=r && s[q[r]]>=s[i-L+]) r--;
//加入i-L+1(和之前比右端点向右挪了一位)
q[++r]=i-L+;
while(i-q[l]+>R && l <= r) l++;//排除非法
if(l<=r) ans=max(ans,s[i]-s[q[l]]);
}
return ans>m*k;
} inline bool judge(double m)
{
for(res i= ; i<=n ; i++)
s[i]=s[i-]+(double)d[i]-m;
return check(m);
}
int main()
{
freopen("average.in","r",stdin);
freopen("average.out","w",stdout);
int T=read();
while(T--)
{
double maxn(0.0);
n=read(); k=read(); L=read(); R=read();
for(res i= ; i<=n ; i++) a[i]=read();
for(res i= ; i<=n ; i++) d[i]=a[i]-a[i-];
double l=,r=1e9+;
int head(),tail(),head1(),tail1();
double ans(-100000000.0);
//特殊情况,取得最大值与最小值的两端点之间的距离小于L
//此处用线段树也可以
for(res i= ; i<=n ; i++)
{
while((head<=tail) && (a[q[tail]]>a[i])) tail--;
q[++tail]=i;
while((head1<=tail1) && (a[q1[tail1]]<a[i])) tail1--;
q1[++tail1]=i;
while((head<=tail) && i-q[head]+ > L) head++;
while((head1<=tail1) &&i-q1[head1]+ > L) head1++;
ans=max(ans,(double)(a[q1[head1]]-a[q[head]]) / (double)(L+k-));
}
while(r-l>0.0000001)
{
double mid=(l+r)/;
if(judge(mid)) l=mid,ans=max(ans,l);
else r=mid;
}
//翻转过来,再求一遍,即在刚才的右端点处取得最小s
reverse(a+,a+n+);
for(res i= ; i<=n ; i++) d[i]=a[i]-a[i-];
l=,r=1e9+;
while(r-l>0.0000001)
{
double mid=(l+r)/2.0;
if(judge(mid)) l=mid,ans=max(ans,l);
else r=mid;
}
printf("%.4lf\n",ans);
}
return ;
}