QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#329621 | #1880. Nikanor Loves Games | wsc2008 | WA | 1ms | 3580kb | C++14 | 1.9kb | 2024-02-16 23:10:32 | 2024-02-16 23:10:33 |
Judging History
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(){
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;
}
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3580kb
input:
2 1 4 15 3 5 10
output:
10
result:
wrong answer 1st numbers differ - expected: '2.5000000', found: '10.0000000', error = '3.0000000'