RT,WA on #10,submission
从昨晚到现在还没过,跟第一篇题解各种范围的数据都拍过了。或许需要一些对拍技巧...有没有大佬帮忙看看或者拍一下给组数据 /kel
#include<bits/stdc++.h>
#define il inline
using namespace std;
il long long read()
{
long long xr=0,F=1; char cr;
while(cr=getchar(),cr<'0'||cr>'9') if(cr=='-') F=-1;
while(cr>='0'&&cr<='9')
xr=(xr<<3)+(xr<<1)+(cr^48),cr=getchar();
return xr*F;
}
#define int long long
const double eps=1e-9;
const int N=1.5e5+5;
int n;
struct node
{
int p,t;
double d;
}a[N];
int sum[N],st[N],ed[N],b[N];
il bool cmp(node x,node y) {return x.d>y.d;}
il bool cmp2(int x,int y) {return a[x].p<a[y].p;}
il double get(int id,int t,double c)
{
return 1.0*a[id].p*(1-1.0*c*t/sum[n]);
}
double mx[N];
il bool check(double c)
{
int lst=0;
for(int i=1;i<=n;i++) mx[i]=get(b[i],st[b[i]],c);
for(int i=2;i<=n;i++) mx[i]=max(mx[i],mx[i-1]);
for(int i=1;i<=n;i++)
{
if(a[b[i]].p!=a[b[i-1]].p) lst=i-1;
if(get(b[i],ed[b[i]],c)<mx[lst]) return 0;
}
return 1;
}
signed main()
{
n=read();
for(int i=1;i<=n;i++) a[i].p=read(),b[i]=i;
for(int i=1;i<=n;i++) a[i].t=read(),a[i].d=1.0*a[i].p/a[i].t;
sort(a+1,a+n+1,cmp),sort(b+1,b+n+1,cmp2);
int lst=1;
for(int i=1;i<=n+1;i++)
{
// cerr<<a[i].d<<endl;
sum[i]=sum[i-1]+a[i].t;
if(fabs(a[i].d-a[i-1].d)<eps) st[i]=st[i-1];
else
{
// cerr<<"qwq"<<endl;
for(int j=lst;j<i;j++) ed[j]=sum[i-1];
lst=i,st[i]=sum[i-1];
}
}
for(int i=1;i<=n;i++) st[i]+=a[i].t;
double l=0,r=1;
while(r-l>1e-6)
{
double mid=(l+r)/2;
if(check(mid)) l=mid;
else r=mid;
}
printf("%.8lf\n",l);
return 0;
}
gen:
#include<bits/stdc++.h>
#define il inline
using namespace std;
il int read()
{
int xr=0,F=1; char cr;
while(cr=getchar(),cr<'0'||cr>'9') if(cr=='-') F=-1;
while(cr>='0'&&cr<='9')
xr=(xr<<3)+(xr<<1)+(cr^48),cr=getchar();
return xr*F;
}
int main()
{
srand(time(0)^random_device()());
int n=150000,w1=rand()%1000+100,w2=rand()%1000+100;
cout<<n<<endl;
for(int i=1;i<=n;i++) cout<<rand()%w1+1<<" ";
cout<<endl;
for(int i=1;i<=n;i++) cout<<rand()%w2+1<<" ";
cout<<endl;
return 0;
}