QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#329620#1880. Nikanor Loves Gameswsc2008Compile Error//C++143.8kb2024-02-16 23:10:132024-02-16 23:10:13

Judging History

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

  • [2024-02-16 23:10:13]
  • 评测
  • [2024-02-16 23:10:13]
  • 提交

answer

#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define pii pair<ll,ll>
#define rep(i,a,b) for(ll i=(a);i<=(b);++i)
#define per(i,a,b) for(ll i=(a);i>=(b);--i)
using namespace std;
ll read(){
	ll x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
void write(ll x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);
	putchar(x%10+'0');
}
const ll N=5e5+9,INF=1e18;
ll n,a[N],b[N],x[N],tot,va[N],vb[N],pre[N*2],q[N*2],l=1,r,vv[N*2];
struct Node{
	ll x,v;
}t[N*2],c[N*2],d[N*2];
ld slope(ll i,ll j){
	ll xa=c[i].x,ya=c[i].v,xb=c[j].x,yb=c[j].v;
	if(xa==xb)return -INF;
	return (ya-yb)*1.0/(xb-xa);
}
ll getp(ll x){
	ll l=1,r=tot,p=0;
	while(l<=r){
		ll mid=(l+r)>>1;
		if(vv[mid]<=x)p=mid,l=mid+1;
		else r=mid-1;
	}
	return p;
}
int main(){
	freopen("gamble.in","r",stdin);
	freopen("gamble.out","w",stdout);
	n=read();
	rep(i,1,n)a[i]=read(),b[i]=read(),x[i]=read();
	rep(i,1,n)t[++tot]=(Node){a[i],x[i]},t[++tot]=(Node){b[i],x[i]};
	sort(t+1,t+tot+1,[&](Node a,Node b){
		return a.x<b.x||(a.x==b.x&&a.v<b.v);
	});
	ll ru=0;
	rep(i,1,n)ru+=4*x[i];
	rep(i,1,tot)pre[i]=pre[i-1]+t[i].v,vv[i]=t[i].x;
	rep(i,1,n){
		ll p=getp(a[i]);
		va[i]=pre[p]*2;
		p=getp(b[i]);
		vb[i]=pre[p]*2;
	} 
	ll ans=-INF;
	b[0]=1;
	rep(i,0,n)c[i]=(Node){-4*b[i],vb[i]};
	rep(i,1,n)c[i+n]=(Node){-4*a[i],va[i]}; 
	rep(i,0,n)d[i]=(Node){b[i],vb[i]};
	rep(i,1,n)d[i+n]=(Node){a[i],va[i]}; 
	n*=2; 
	sort(c+0,c+n+1,[&](Node a,Node b){
		return a.x<b.x;
	});
	sort(d+0,d+n+1,[&](Node a,Node b){
		return a.x<b.x;
	}); 
	rep(i,0,n){
		while(l+1<=r&&slope(q[r-1],q[r])>=slope(q[r],i))r--;
		q[++r]=i;
	}
	rep(i,0,n){
		while(l+1<=r&&slope(q[l],q[l+1])<d[i].x)l++;
		ans=max(ans,d[i].v+c[q[l]].v+c[q[l]].x*d[i].x);
	}
//	cout<<fixed<<setprecision(12)<<(ans-ru)*0.25;
	write(ans-ru);
	return 0;
}#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define pii pair<ll,ll>
#define rep(i,a,b) for(ll i=(a);i<=(b);++i)
#define per(i,a,b) for(ll i=(a);i>=(b);--i)
using namespace std;
ll read(){
	ll x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
void write(ll x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);
	putchar(x%10+'0');
}
const ll N=5e5+9,INF=1e18;
ll n,a[N],b[N],x[N],tot,va[N],vb[N],pre[N*2],q[N*2],l=1,r,vv[N*2];
struct Node{
	ll x,v;
}t[N*2],c[N*2],d[N*2];
ld slope(ll i,ll j){
	ll xa=c[i].x,ya=c[i].v,xb=c[j].x,yb=c[j].v;
	if(xa==xb)return -INF;
	return (ya-yb)*1.0/(xb-xa);
}
ll getp(ll x){
	ll l=1,r=tot,p=0;
	while(l<=r){
		ll mid=(l+r)>>1;
		if(vv[mid]<=x)p=mid,l=mid+1;
		else r=mid-1;
	}
	return p;
}
int main(){
	n=read();
	rep(i,1,n)a[i]=read(),b[i]=read(),x[i]=read();
	rep(i,1,n)t[++tot]=(Node){a[i],x[i]},t[++tot]=(Node){b[i],x[i]};
	sort(t+1,t+tot+1,[&](Node a,Node b){
		return a.x<b.x||(a.x==b.x&&a.v<b.v);
	});
	ll ru=0;
	rep(i,1,n)ru+=4*x[i];
	rep(i,1,tot)pre[i]=pre[i-1]+t[i].v,vv[i]=t[i].x;
	rep(i,1,n){
		ll p=getp(a[i]);
		va[i]=pre[p]*2;
		p=getp(b[i]);
		vb[i]=pre[p]*2;
	} 
	ll ans=-INF;
	b[0]=1;
	rep(i,0,n)c[i]=(Node){-4*b[i],vb[i]};
	rep(i,1,n)c[i+n]=(Node){-4*a[i],va[i]}; 
	rep(i,0,n)d[i]=(Node){b[i],vb[i]};
	rep(i,1,n)d[i+n]=(Node){a[i],va[i]}; 
	n*=2; 
	sort(c+0,c+n+1,[&](Node a,Node b){
		return a.x<b.x;
	});
	sort(d+0,d+n+1,[&](Node a,Node b){
		return a.x<b.x;
	}); 
	rep(i,0,n){
		while(l+1<=r&&slope(q[r-1],q[r])>slope(q[r],i))r--;
		q[++r]=i;
	}
	rep(i,0,n){
		while(l+1<=r&&slope(q[l],q[l+1])<d[i].x)l++;
		ans=max(ans,d[i].v+c[q[l]].v+c[q[l]].x*d[i].x);
	}
	cout<<fixed<<setprecision(12)<<(ans-ru)*0.25;
	//write(ans-ru);
	return 0;
}

详细

answer.code:81:2: error: stray ‘#’ in program
   81 | }#include<bits/stdc++.h>
      |  ^
answer.code:81:3: error: ‘include’ does not name a type
   81 | }#include<bits/stdc++.h>
      |   ^~~~~~~
answer.code:89:4: error: redefinition of ‘ll read()’
   89 | ll read(){
      |    ^~~~
answer.code:9:4: note: ‘ll read()’ previously defined here
    9 | ll read(){
      |    ^~~~
answer.code:95:6: error: redefinition of ‘void write(ll)’
   95 | void write(ll x){
      |      ^~~~~
answer.code:15:6: note: ‘void write(ll)’ previously defined here
   15 | void write(ll x){
      |      ^~~~~
answer.code:100:10: error: redefinition of ‘const ll N’
  100 | const ll N=5e5+9,INF=1e18;
      |          ^
answer.code:20:10: note: ‘const ll N’ previously defined here
   20 | const ll N=5e5+9,INF=1e18;
      |          ^
answer.code:100:18: error: redefinition of ‘const ll INF’
  100 | const ll N=5e5+9,INF=1e18;
      |                  ^~~
answer.code:20:18: note: ‘const ll INF’ previously defined here
   20 | const ll N=5e5+9,INF=1e18;
      |                  ^~~
answer.code:101:4: error: redefinition of ‘ll n’
  101 | ll n,a[N],b[N],x[N],tot,va[N],vb[N],pre[N*2],q[N*2],l=1,r,vv[N*2];
      |    ^
answer.code:21:4: note: ‘ll n’ previously declared here
   21 | ll n,a[N],b[N],x[N],tot,va[N],vb[N],pre[N*2],q[N*2],l=1,r,vv[N*2];
      |    ^
answer.code:101:6: error: redefinition of ‘ll a [500009]’
  101 | ll n,a[N],b[N],x[N],tot,va[N],vb[N],pre[N*2],q[N*2],l=1,r,vv[N*2];
      |      ^
answer.code:21:6: note: ‘ll a [500009]’ previously declared here
   21 | ll n,a[N],b[N],x[N],tot,va[N],vb[N],pre[N*2],q[N*2],l=1,r,vv[N*2];
      |      ^
answer.code:101:11: error: redefinition of ‘ll b [500009]’
  101 | ll n,a[N],b[N],x[N],tot,va[N],vb[N],pre[N*2],q[N*2],l=1,r,vv[N*2];
      |           ^
answer.code:21:11: note: ‘ll b [500009]’ previously declared here
   21 | ll n,a[N],b[N],x[N],tot,va[N],vb[N],pre[N*2],q[N*2],l=1,r,vv[N*2];
      |           ^
answer.code:101:16: error: redefinition of ‘ll x [500009]’
  101 | ll n,a[N],b[N],x[N],tot,va[N],vb[N],pre[N*2],q[N*2],l=1,r,vv[N*2];
      |                ^
answer.code:21:16: note: ‘ll x [500009]’ previously declared here
   21 | ll n,a[N],b[N],x[N],tot,va[N],vb[N],pre[N*2],q[N*2],l=1,r,vv[N*2];
      |                ^
answer.code:101:21: error: redefinition of ‘ll tot’
  101 | ll n,a[N],b[N],x[N],tot,va[N],vb[N],pre[N*2],q[N*2],l=1,r,vv[N*2];
      |                     ^~~
answer.code:21:21: note: ‘ll tot’ previously declared here
   21 | ll n,a[N],b[N],x[N],tot,va[N],vb[N],pre[N*2],q[N*2],l=1,r,vv[N*2];
      |                     ^~~
answer.code:101:25: error: redefinition of ‘ll va [500009]’
  101 | ll n,a[N],b[N],x[N],tot,va[N],vb[N],pre[N*2],q[N*2],l=1,r,vv[N*2];
      |                         ^~
answer.code:21:25: note: ‘ll va [500009]’ previously declared here
   21 | ll n,a[N],b[N],x[N],tot,va[N],vb[N],pre[N*2],q[N*2],l=1,r,vv[N*2];
      |                         ^~
answer.code:101:31: error: redefinition of ‘ll vb [500009]’
  101 | ll n,a[N],b[N],x[N],tot,va[N],vb[N],pre[N*2],q[N*2],l=1,r,vv[N*2];
      |                               ^~
answer.code:21:31: note: ‘ll vb [500009]’ previously declared here
   21 | ll n,a[N],b[N],x[N],tot,va[N],vb[N],pre[N*2],q[N*2],l=1,r,vv[N*2];
      |                               ^~
answer.code:101:37: error: redefinition of ‘ll pre [1000018]’
  101 | ll n,a[N],b[N],x[N],tot,va[N],vb[N],pre[N*2],q[N*2],l=1,r,vv[N*2];
      |                                     ^~~
answer.code:21:37: note: ‘ll pre [1000018]’ previously declared here
   21 | ll n,a[N],b[N],x[N],tot,va[N],vb[N],pre[N*2],q[N*2],l=1,r,vv[N*2];
      |                                     ^~~
answer.code:101:46: error: redefinition of ‘ll q [1000018]’
  101 | ll n,a[N],b[N],x[N],tot,va[N],vb[N],pre[N*2],q[N*2],l=1,r,vv[N*2];
      |                                              ^
answer.code:21:46: note: ‘ll q [1000018]’ previously declared here
   21 | ll n,a[N],b[N],x[N],tot,va[N],vb[N],pre[N*2],q[N*2],l=1,r,vv[N*2];
      |                                              ^
answer.code:101:53: error: redefinition of ‘ll l’
  101 | ll n,a[N],b[N],x[N],tot,va[N],vb[N],pre[N*2],q[N*2],l=1,r,vv[N*2];
      |                                                     ^
answer.code:21:53: note: ‘ll l’ previously defined here
   21 | ll n,a[N],b[N],x[N],tot,va[N],vb[N],pre[N*2],q[N*2],l=1,r,vv[N*2];
      |                                                     ^
answer.code:101:57: error: redefinition of ‘ll r’
  101 | ll n,a[N],b[N],x[N],tot,va[N],vb[N],pre[N*2],q[N*2],l=1,r,vv[N*2];
      |                                                         ^
answer.code:21:57: note: ‘ll r’ previously declared here
   21 | ll n,a[N],b[N],x[N],tot,va[N],vb[N],pre[N*2],q[N*2],l=1,r,vv[N*2];
      |                                                         ^
answer.code:101:59: error: redefinition of ‘ll vv [1000018]’
  101 | ll n,a[N],b[N],x[N],tot,va[N],vb[N],pre[N*2],q[N*2],l=1,r,vv[N*2];
      | ...