QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#559421 | #5433. Absolute Difference | Wuyanru | WA | 1ms | 8020kb | C++14 | 2.8kb | 2024-09-11 21:58:11 | 2024-09-11 21:58:18 |
Judging History
answer
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f3f3f3f3fll
#define debug(x) cerr<<#x<<"="<<x<<endl
using namespace std;
using ll=long long;
using ld=long double;
using pli=pair<ll,int>;
using pi=pair<int,int>;
template<typename A>
using vc=vector<A>;
using pd=pair<ld,ld>;
inline int read()
{
int s=0,w=1;char ch;
while((ch=getchar())>'9'||ch<'0') if(ch=='-') w=-1;
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
inline ll lread()
{
ll s=0,w=1;char ch;
while((ch=getchar())>'9'||ch<'0') if(ch=='-') w=-1;
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
const ld L=1000000000000000000ll;
ld num[400005];
int numa[400005];
int numb[400005];
int len;
inline ld get(int *a,int *b)
{
ld ans=0,lena=0,suma=0,lenb=0,sumb=0;
for(int i=1;i<=len;i++)
{
ld l=num[i],r=num[i+1];
if(a[i]) lena+=r-l,suma+=(r-l)*(l+r)/2;
if(b[i]) lenb+=r-l,sumb+=(r-l)*(l+r)/2;
}
suma/=lena,sumb/=lenb;
// printf("%Lf %Lf %Lf %Lf\n",lena,suma,lenb,sumb);
ld P=0;
for(int i=1;i<=len;i++)
{
ld l=num[i],r=num[i+1];
ld Pb=(r-l)/lenb,Pa=(r-l)/lena;
if(a[i])
{
ans+=P*Pa*(l+r)/2;
// printf("i=%d ans=%Lf\n",i,ans);
if(b[i])
{
ld t=r*r*r/3-l*l*l/3-l*r*r/2+l*l*l/2;
ans+=t/lena/lenb;
}
// printf("i=%d ans=%Lf\n",i,ans);
}
if(b[i]) P+=Pb;
}
return 2*ans-suma;
}
int main()
{
int n=read(),m=read();
vc<pd>Sa,Sb;ld ma=0;
for(int i=1;i<=n;i++){ ld l=num[++len]=lread()*L,r=lread()*L;Sa.push_back(pd(l,r)),ma=max(ma,r-l);}
for(int i=1;i<=m;i++){ ld l=num[++len]=lread()*L,r=lread()*L;Sb.push_back(pd(l,r)),ma=max(ma,r-l);}
for(int i=1;i<=n;i++) num[++len]=Sa[i-1].second=Sa[i-1].second+ma/L+1;
for(int i=1;i<=m;i++) num[++len]=Sb[i-1].second=Sb[i-1].second+ma/L+1;
// for(auto i:Sa) printf("(%Lf,%Lf) ",i.first,i.second);;putchar('\n');
// for(auto i:Sb) printf("(%Lf,%Lf) ",i.first,i.second);;putchar('\n');
sort(num+1,num+len+1),len=unique(num+1,num+len+1)-num-1;
for(auto i:Sa)
{
int l=lower_bound(num+1,num+len+1,i.first)-num;
int r=lower_bound(num+1,num+len+1,i.second)-num;
for(int j=l;j<r;j++) numa[j]=1;
}
for(auto i:Sb)
{
int l=lower_bound(num+1,num+len+1,i.first)-num;
int r=lower_bound(num+1,num+len+1,i.second)-num;
for(int j=l;j<r;j++) numb[j]=1;
}
// for(int i=1;i<=len;i++) printf("%Lf ",num[i]);;putchar('\n');
// for(int i=1;i<=len;i++) printf("%d ",numa[i]);;putchar('\n');
// for(int i=1;i<=len;i++) printf("%d ",numb[i]);;putchar('\n');
printf("%.20Lf\n",(get(numa,numb)+get(numb,numa))/L);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 6128kb
input:
1 1 0 1 0 1
output:
0.33333333333333333413
result:
ok found '0.333333333', expected '0.333333333', error '0.000000000'
Test #2:
score: 0
Accepted
time: 1ms
memory: 5896kb
input:
1 1 0 1 1 1
output:
0.49999999999999999599
result:
ok found '0.500000000', expected '0.500000000', error '0.000000000'
Test #3:
score: 0
Accepted
time: 1ms
memory: 6116kb
input:
1 1 -1000000000 1000000000 -1000000000 1000000000
output:
666666666.66666666744276881218
result:
ok found '666666666.666666627', expected '666666666.666666627', error '0.000000000'
Test #4:
score: 0
Accepted
time: 1ms
memory: 8016kb
input:
1 1 -1000000000 0 0 1000000000
output:
999999999.99999999994179233909
result:
ok found '1000000000.000000000', expected '1000000000.000000000', error '0.000000000'
Test #5:
score: 0
Accepted
time: 1ms
memory: 6012kb
input:
1 1 -1000000000 -1000000000 -1000000000 1000000000
output:
1000000000.00000000203726813197
result:
ok found '1000000000.000000000', expected '1000000000.000000000', error '0.000000000'
Test #6:
score: 0
Accepted
time: 0ms
memory: 5780kb
input:
1 1 -999999999 1000000000 -1000000000 -1000000000
output:
1000000000.50000000000000000000
result:
ok found '1000000000.500000000', expected '1000000000.500000000', error '0.000000000'
Test #7:
score: 0
Accepted
time: 0ms
memory: 8020kb
input:
1 1 -1000000000 1000000000 -999999999 -999999999
output:
999999999.00000000256113708019
result:
ok found '999999999.000000000', expected '999999999.000000000', error '0.000000000'
Test #8:
score: -100
Wrong Answer
time: 1ms
memory: 5756kb
input:
1 1 1000000000 1000000000 -1000000000 -1000000000
output:
-nan
result:
wrong output format Expected double, but "-nan" found