QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#712034 | #8524. Weather Forecast | ucup-team4992# | WA | 1ms | 5928kb | C++20 | 1.8kb | 2024-11-05 14:21:55 | 2024-11-05 14:21:55 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
const double eps=1e-9;
int a[maxn];
int o[maxn<<2];
double sum[maxn],f[maxn];
int n,k;
void build(int p,int l,int r){
if(l==r){
o[p]=-1e9;
return;
}
int mid=l+r>>1;
build(p<<1,l,mid);
build(p<<1|1,mid+1,r);
o[p]=-1e9;
}
void update(int p,int l,int r,int x,int y){
if(l==r){
o[p]=y;
return;
}
int mid=l+r>>1;
if(x<=mid) update(p<<1,l,mid,x,y);
if(x>mid) update(p<<1|1,mid+1,r,x,y);
o[p]=max(o[p<<1],o[p<<1|1]);
}
int query(int p,int l,int r,int x,int y){
if(x>y) return -1e9;
if(x<=l&&r<=y){
return o[p];
}
int mid=l+r>>1;
int res=0;
if(x<=mid) res=max(res,query(p<<1,l,mid,x,y));
if(y>mid) res=max(res,query(p<<1|1,mid+1,r,x,y));
return res;
}
bool check(double mid){
for(int i=1;i<=n;i++) f[i]=sum[i]-i*mid;
build(1,1,n);
vector<int>rnk(n+1);
iota(rnk.begin()+1,rnk.end(),1);
sort(rnk.begin()+1,rnk.end(),[&](int i,int j){
return f[i]<f[j]||f[i]==f[j]&&i<j;
});
for(int i=1;i<=n;i++){
// cout<<rnk[i]<<' ';
int res=query(1,1,n,1,rnk[i]-1);
// cout<<res<<' ';
update(1,1,n,rnk[i],res+1);
}
// cout<<'\n';
// cout<<query(1,1,n,n,n)<<'\n';
return query(1,1,n,n,n)>=k;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin>>n>>k;
for(int i=1;i<=n;i++) cin>>a[i],sum[i]=sum[i-1]+a[i];
double evg=double(sum[n])/n;
double l=1,r=evg-eps;
while(r-l>eps){
double mid=(l+r)/2;
// cout<<mid<<'\n';
if(check(mid)) l=mid;
else r=mid;
}
cout<<fixed<<setprecision(9)<<l<<'\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5928kb
input:
7 3 1 3 1 2 2 2 1
output:
1.666666667
result:
ok found '1.66667', expected '1.66667', error '0.00000'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3784kb
input:
1 1 1
output:
1.000000000
result:
ok found '1.00000', expected '1.00000', error '0.00000'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3888kb
input:
2 1 2 1
output:
1.499999998
result:
ok found '1.50000', expected '1.50000', error '0.00000'
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 5864kb
input:
3 2 2 4 4
output:
3.333333332
result:
wrong answer 1st numbers differ - expected: '3.00000', found: '3.33333', error = '0.33333'