QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#707113#9540. Double 11ucup-team5319Compile Error//C++142.5kb2024-11-03 14:44:072024-11-03 14:44:07

Judging History

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

  • [2024-11-03 14:44:07]
  • 评测
  • [2024-11-03 14:44:07]
  • 提交

answer

//Linkwish's code
#include<bits/stdc++.h>
#define endl '\n'
#define si inline
#define fi first
#define se second
using namespace std;
typedef long long ll;typedef __int128 li;typedef long double ld;
typedef pair<int,int> pii;typedef pair<ll,ll> pll;
typedef const int ci;typedef const ll cl;ci iinf=INT_MAX;cl linf=LLONG_MAX;
template<typename T>si bool gmax(T &x,const T y){if(x<y)return x=y,1;return 0;}
template<typename T>si bool gmin(T &x,const T y){if(y<x)return x=y,1;return 0;}

namespace LinkWish{

	ci N=200005,eps=1e-12;
	si int sign(ld x){
		if(x<-eps)return -1;
		if(x>eps)return 1;
		return 0;
	}

	int n,m;
	ld a[N],sum[N];

	ld f[N];int g[N];

	si ld w(int l,int r){
		return sqrtl((sum[r]-sum[l])/(r-l))*(r-l);
	}

	int q[N],head,tail;
	int L[N],R[N];
	si pair<ld,int> calc(ld k){
		//cout<<"CAL "<<fixed<<setprecision(10)<<k<<endl;

		f[0]=0,g[0]=0;
		q[head=tail=1]=0,L[0]=1,R[0]=n;
		for(int i=1;i<=n;i++){
			//f[i]=1e18;
			//for(int j=0;j<i;j++)if(gmin(f[i],f[j]+w(j,i)+k))g[i]=g[j]+1;
			//cout<<"GETI "<<i<<' '<<f[i]<<' '<<g[i]<<endl;
			for(;head<=tail&&i>R[q[head]];head++);
			f[i]=f[q[head]]+w(q[head],i)+k,g[i]=g[q[head]]+1;

			//cout<<"GETI "<<i<<' '<<q[head]<<' '<<w(q[head],i)<<' '<<f[i]<<' '<<g[i]<<endl;

			auto getp=[&](int x){
				int l=max(i+1,L[x]),r=n,mid,res=-1;
				while(l<=r){
					mid=(l+r)>>1;
					if(sign((f[x]+w(x,mid))-(f[i]+w(i,mid)))!=-1)res=mid,r=mid-1;
					else l=mid+1;
				}
				return res;
			};
			bool flag=true;
			while(head<=tail){
				int x=q[tail],pos=getp(x);
				//if(~pos)cout<<"PO "<<x<<' '<<pos<<' '<<f[x]+w(x,pos)<<' '<<f[i]+w(i,pos)<<endl;
				if(pos==-1){
					flag=false;
					break;
				}
				if(pos==L[x])tail--;
				else{
					R[x]=pos-1,L[i]=pos,R[i]=n;
					break;
				}
			}
			if(flag)q[++tail]=i;
		}

		return make_pair(f[n],g[n]);
	}
	
	void mian(){
		cin>>n>>m;

		for(int i=1;i<=n;i++){
			int x;cin>>x;
			a[i]=x;
		}
		sort(a+1,a+1+n);
		for(int i=1;i<=n;i++)sum[i]=sum[i-1]+a[i];

		ld lim=sqrtl(sum[n])*1.2;

		lld ans=1e18;
		ld l=-lim,r=lim,mid;
		for(int i=1;i<=60;i++){
			mid=(l+r)/2;
			auto res=calc(mid);
			if(res.se<=m){
				if(res.se<=m)gmin(ans,res.fi-res.se*mid);
				r=mid;
			}
			else l=mid;
		}

		long double Ans=ans;
		cout<<fixed<<setprecision(10)<<Ans<<endl;
	}
}

signed main(){
	#ifndef ONLINE_JUDGE
	assert(freopen("in.in","r",stdin));
	assert(freopen("out.out","w",stdout));
	#endif
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	LinkWish::mian();
	return 0;
}

详细

answer.code: In function ‘void LinkWish::mian()’:
answer.code:89:17: error: ‘lld’ was not declared in this scope; did you mean ‘ll’?
   89 |                 lld ans=1e18;
      |                 ^~~
      |                 ll
answer.code:95:51: error: ‘ans’ was not declared in this scope; did you mean ‘abs’?
   95 |                                 if(res.se<=m)gmin(ans,res.fi-res.se*mid);
      |                                                   ^~~
      |                                                   abs
answer.code:101:33: error: ‘ans’ was not declared in this scope; did you mean ‘Ans’?
  101 |                 long double Ans=ans;
      |                                 ^~~
      |                                 Ans