QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#442892#8524. Weather Forecastucup-team3282#WA 1ms10072kbC++141.9kb2024-06-15 13:46:272024-06-15 13:46:32

Judging History

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

  • [2024-06-15 13:46:32]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:10072kb
  • [2024-06-15 13:46:27]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+10;
const int K=1e5;
const ll maxs=2e13;

int n,k;
ll a[maxn],s[maxn];
int f[maxn];

struct seg_tree{
	int cnt=0;
	int ls[maxn<<5],rs[maxn<<5];
	int mx[maxn<<5];
	void build(){
		for(int i=1;i<=cnt;i++)
			ls[i]=rs[i]=mx[i]=0;
		cnt=0;
	}
	void push_up(int u){
		mx[u]=max(mx[ls[u]],mx[rs[u]]);
	}
	void f(int& u,int x){
		if(u==0)
			u=++cnt;
		mx[u]=x;
	}
	void modify(int& u,ll L,ll R,ll l,ll r,int x){
		if(u==0)
			u=++cnt;
//		cout<<"modify "<<u<<' '<<L<<' '<<R<<' '<<l<<' '<<r<<' '<<x<<endl;
		if(L==l&&R==r){
			mx[u]=x;
			return;
		}
		ll mid=(L+R)>>1;
		if(l<=mid){
			f(ls[u],x);
			modify(ls[u],L,mid,l,r,x);
		}
		if(mid+1<=r){
			f(rs[u],x);
			modify(rs[u],mid+1,R,l,r,x);
		}
		push_up(u);
	}
	int query(int u,ll L,ll R,ll l,ll r){
		if(u==0)
			return -1;
		if(l<=L&&R<=r)
			return mx[u];
		ll mid=(L+R)>>1;
		int res=-1;
		if(l<=mid)
			res=max(query(ls[u],L,mid,l,r),res);
		if(mid+1<=r)
			res+=max(query(rs[u],mid+1,R,l,r),res);
		return res;
	}
}st;
bool check(ll x){
	for(int i=1;i<=n;i++)
		a[i]-=x;
	for(int i=1;i<=n;i++)
		s[i]=s[i-1]+a[i];
	st.build();
//	for(int i=1;i<=n;i++)cout<<a[i]<<' ';cout<<endl;
	int rt=0;
	st.modify(rt,-maxs,maxs,-maxs,maxs,-1);
	st.modify(rt,-maxs,maxs,0,0,0);
	for(int i=1;i<=n;i++){
		f[i]=st.query(rt,-maxs,maxs,-maxs,s[i])+1;
		st.modify(rt,-maxs,maxs,s[i],s[i],f[i]);
	}
	for(int i=1;i<=n;i++)
		a[i]+=x;
	return f[n]>=k;
}

int main(){
	ios::sync_with_stdio(0);
	cin>>n>>k;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++)
		a[i]*=K;
	
	ll l=0,r=1e3*K,mid,ans=-1;
	while(l<=r){
		mid=(l+r)/2;
		if(check(mid)){
			ans=mid;
			l=mid+1;
		}
		else{
			r=mid-1;
		}
	}
	cout<<fixed<<setprecision(5)<<((double)ans/K)<<endl;
	
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 7936kb

input:

7 3
1 3 1 2 2 2 1

output:

1.66666

result:

ok found '1.66666', expected '1.66667', error '0.00001'

Test #2:

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

input:

1 1
1

output:

1.00000

result:

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

Test #3:

score: 0
Accepted
time: 1ms
memory: 7928kb

input:

2 1
2 1

output:

1.50000

result:

ok found '1.50000', expected '1.50000', error '0.00000'

Test #4:

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

input:

3 2
2 4 4

output:

3.00000

result:

ok found '3.00000', expected '3.00000', error '0.00000'

Test #5:

score: 0
Accepted
time: 1ms
memory: 7984kb

input:

4 2
6 7 3 12

output:

6.50000

result:

ok found '6.50000', expected '6.50000', error '0.00000'

Test #6:

score: -100
Wrong Answer
time: 1ms
memory: 5884kb

input:

5 3
17 23 13 12 21

output:

17.00000

result:

wrong answer 1st numbers differ - expected: '16.50000', found: '17.00000', error = '0.50000'