QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#603740#8524. Weather ForecastUKBwyxWA 2ms16688kbC++141.7kb2024-10-01 18:43:532024-10-01 18:43:53

Judging History

你现在查看的是最新测评结果

  • [2024-10-01 18:43:53]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:16688kb
  • [2024-10-01 18:43:53]
  • 提交

answer

#include<bits/stdc++.h>
#define float double
using namespace std;
long long n;
struct jd {
	int v=0,l,r;
};
struct xds {
	jd a[800005];
	void csh1(int wz,int l1,int r1) {
		a[wz].l=l1;
		a[wz].r=r1;
		a[wz].v=-1<<30;
		if(l1==r1) {
			return;
		}
		csh1(wz<<1,l1,(r1+l1)/2);
		csh1(wz<<1|11,(r1+l1)/2+1,r1);
	}
	void csh() {
		csh1(1,0,n);
	}
	void change(int wz,int wz1,int z) {
		if(a[wz].l==a[wz].r) {
			a[wz].v=max(z,a[wz].v);
			return;
		}
		if(wz1>=a[wz*2+1].l) {
			change(wz<<1|1,wz1,z);
		} else {
			change(wz<<1,wz1,z);
		}
		a[wz].v=max(a[wz<<1|1].v,a[wz<<1].v);
	}
	int check(int wz,int l1,int r1) {
		if(a[wz].l>=l1&&a[wz].r<=r1) {
			return a[wz].v;
		}
		int t=-1<<30;
		if(l1<a[wz*2+1].l) {
			t=max(t,check(wz<<1,l1,r1));
		}
		if(r1>a[wz*2].r) {
			t=max(t,check(wz<<1|1,l1,r1));
		}
		return t;
	}
};
long long k,a[200005],u[200005];
float qz[200005],b[200005];
xds c;
bool check(double x) {
	b[0]=0;
	for(int i=1; i<=n; i++) {
		qz[i]=qz[i-1]+(a[i]-x);
		b[i]=qz[i];
	}
	sort(b,b+n+1);
	map<float,int>m1;
	for(int i=0; i<=n; i++) {
		m1[b[i]]=i;
	}
	c.csh();
	c.change(1,m1[0],0);
	for(int i=1; i<=n; i++) {
		int w=m1[qz[i]];
		int v=c.check(1,0,w);
		u[i]=++v;
		c.change(1,w,v);
	}
	return u[n]>=k;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>k;
	double ma=0;
	long long mi=1e18;
	for(int i=1; i<=n; i++) {
		cin>>a[i];
		ma+=a[i];
		mi=min(mi,a[i]);
	}
	ma/=n;
	double lim=0.000001,l=mi-lim,r=ma+lim,ans=0;
	while(l+lim<=r) {
		double mid=(l+r)*0.5;
		if(check(mid)) {
			l=mid;
			ans=max(ans,mid);
		} else {
			r=mid;
		}
	}
	printf("%.7f",ans);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 16004kb

input:

7 3
1 3 1 2 2 2 1

output:

1.6666662

result:

ok found '1.66667', expected '1.66667', error '0.00000'

Test #2:

score: 0
Accepted
time: 0ms
memory: 15928kb

input:

1 1
1

output:

1.0000000

result:

ok found '1.00000', expected '1.00000', error '0.00000'

Test #3:

score: -100
Wrong Answer
time: 2ms
memory: 16688kb

input:

2 1
2 1

output:

1.0000000

result:

wrong answer 1st numbers differ - expected: '1.50000', found: '1.00000', error = '0.50000'