QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#360116 | #5433. Absolute Difference | qwqUwU_ | WA | 1ms | 8084kb | C++14 | 3.4kb | 2024-03-21 12:32:33 | 2024-03-21 12:32:34 |
Judging History
answer
// clang-format off
#include<bits/stdc++.h>
#define pb push_back
#define st first
#define nd second
#define bit(s,x) (((s)>>(x))&1)
#define ctz(s) __builtin_popcount(s)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
//typedef __int128 i128;
typedef long double ld;
typedef pair<int,int> pii; typedef pair<ll,int> pli; typedef pair<ll,ll> pll; typedef pair<int,ll> pil;
inline ll read(){
ll x=0,f=1,c=getchar();
while(c<'0'||c>'9')f=(c=='-'?-1:1),c=getchar();
while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
inline void write(ll x){ if(x<0) putchar('-'),x=-x; if(x>9) write(x/10); putchar(x%10+'0'); }
// remember to change!!!
const int mod=998244353;
inline void plust(int &x,int y,int p=mod){x=x+y<p?x+y:x+y-p;}
inline void mul(int &x,int y,int p=mod){x=1ll*x*y%p;}
inline int fp(int x,ll p=mod-2,int m=mod,int res=1){
for(;p;p>>=1){if(p&1)mul(res,x,m);mul(x,x,m);}
return res;
}
const int N=1e5+10;
const int INF=0x3fffffff;
// clang-format on
int n,m;
pll a[N],b[N];
double s[N],sp[N];
double s1=0,s2=0;
inline double P(ll a,ll b){
if(a==0 && b==0)return 1.0;
return 1.0*a/b;
}
inline double f(ll l1,ll r1,ll l2,ll r2){
return abs(r2+l2-l1-r1)*0.5*P(r2-l2,s2)*P(r1-l1,s1);
}
inline double calc(int i,int j){
double res = 0;
if(a[i].st < b[j].st){
if(a[i].nd < b[j].nd){
assert(a[i].st <= b[j].st && b[j].st <= a[i].nd && a[i].nd <= b[j].nd);
res += f(a[i].st,b[j].st,b[j].st,b[j].nd);
res += f(b[j].st,a[i].nd,a[i].nd,b[j].nd);
res += 1.0*(a[i].nd-b[j].st)/3*P(a[i].nd-b[j].st,s2)*P(a[i].nd-b[j].st,s1);
}
else{
assert(a[i].st <= b[j].st && b[j].st <= b[j].nd && b[j].nd <= a[i].nd);
res += f(a[i].st,b[j].st,b[j].st,b[j].nd);
res += f(b[j].nd,a[i].nd,b[j].st,b[j].nd);
res += 1.0*(b[j].nd-b[j].st)/3*P(b[j].nd-b[j].st,s2)*P(b[j].nd-b[j].st,s1);
}
}
else{
if(b[j].nd < a[i].nd){
assert(b[j].st <= a[i].st && a[i].st <= b[j].nd && b[j].nd <= a[i].nd);
res += f(b[j].nd,a[i].nd,b[j].st,b[j].nd);
res += f(a[i].st,b[j].nd,b[j].st,a[i].st);
res += 1.0*(b[j].nd-a[i].st)/3*P(b[j].nd-a[i].st,s1)*P(b[j].nd-a[i].st,s2);
}
else{
assert(b[j].st <= a[i].st && a[i].st <= a[i].nd && a[i].nd <= b[j].nd);
res += f(a[i].st,a[i].nd,b[j].st,a[i].st);
res += f(a[i].st,a[i].nd,a[i].nd,b[j].nd);
res += 1.0*(a[i].nd-a[i].st)/3*P(a[i].nd-a[i].st,s1)*P(a[i].nd-a[i].st,s2);
}
}
return res;
}
int main() {
//freopen("data.in", "r", stdin);
// freopen(".in","r",stdin);
// freopen("myans.out","w",stdout);
n=read(),m=read();
for(int i=1;i<=n;++i)a[i].st=read(),a[i].nd=read(),s1+=a[i].nd-a[i].st;
for(int i=1;i<=m;++i)b[i].st=read(),b[i].nd=read(),s2+=b[i].nd-b[i].st;
sort(a+1,a+n+1),sort(b+1,b+m+1);
for(int i=1;i<=n;++i)s[i]=s[i-1] + (a[i].st+a[i].nd)*0.5*P(a[i].nd-a[i].st,s1);
for(int i=1;i<=n;++i)sp[i]=sp[i-1] + P(a[i].nd-a[i].st,s1);
double ans=0;
for(int i=1,lst1=1,lst2=1;i<=m;++i){
while(lst1<=n && a[lst1].nd < b[i].st)++lst1;
while(lst2<=n && a[lst2].st < b[i].nd)++lst2;
double p2 = P(b[i].nd-b[i].st,s2),res=0;
assert(lst1 <= 1 || a[lst1-1].nd <= b[i].st);
assert(lst2 > n||a[lst2].st >= b[i].nd);
if(lst1 > 1) res += (sp[lst1-1]*(b[i].st+b[i].nd)*0.5 - s[lst1-1])*p2;
if(lst2 <= n) res += (s[n] - s[lst2-1] - (sp[n] - sp[lst2-1])*(b[i].st+b[i].nd)*0.5)*p2;
for(int j=lst1;j<lst2;++j)res += calc(j,i);
ans += res;
}
printf("%.15lf",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5912kb
input:
1 1 0 1 0 1
output:
0.333333333333333
result:
ok found '0.333333333', expected '0.333333333', error '0.000000000'
Test #2:
score: 0
Accepted
time: 1ms
memory: 8016kb
input:
1 1 0 1 1 1
output:
0.500000000000000
result:
ok found '0.500000000', expected '0.500000000', error '0.000000000'
Test #3:
score: 0
Accepted
time: 1ms
memory: 8016kb
input:
1 1 -1000000000 1000000000 -1000000000 1000000000
output:
666666666.666666626930237
result:
ok found '666666666.666666627', expected '666666666.666666627', error '0.000000000'
Test #4:
score: 0
Accepted
time: 1ms
memory: 5976kb
input:
1 1 -1000000000 0 0 1000000000
output:
1000000000.000000119209290
result:
ok found '1000000000.000000119', expected '1000000000.000000000', error '0.000000000'
Test #5:
score: 0
Accepted
time: 0ms
memory: 8024kb
input:
1 1 -1000000000 -1000000000 -1000000000 1000000000
output:
1000000000.000000000000000
result:
ok found '1000000000.000000000', expected '1000000000.000000000', error '0.000000000'
Test #6:
score: 0
Accepted
time: 1ms
memory: 8076kb
input:
1 1 -999999999 1000000000 -1000000000 -1000000000
output:
1000000000.499999880790710
result:
ok found '1000000000.499999881', expected '1000000000.500000000', error '0.000000000'
Test #7:
score: 0
Accepted
time: 0ms
memory: 5976kb
input:
1 1 -1000000000 1000000000 -999999999 -999999999
output:
999999999.000000119209290
result:
ok found '999999999.000000119', expected '999999999.000000000', error '0.000000000'
Test #8:
score: 0
Accepted
time: 1ms
memory: 8084kb
input:
1 1 1000000000 1000000000 -1000000000 -1000000000
output:
2000000000.000000000000000
result:
ok found '2000000000.000000000', expected '2000000000.000000000', error '0.000000000'
Test #9:
score: 0
Accepted
time: 0ms
memory: 5956kb
input:
1000 1000 -2175 -2174 -1068 -1065 -1721 -1718 777 834 1162 1169 -3529 -3524 3966 3993 1934 1952 -234 -223 -4967 -4947 8500 8510 5272 5276 -6048 -6033 -34 -22 700 705 -7890 -7886 5538 5543 4114 4126 -9201 -9162 -1521 -1519 -5103 -5100 439 441 993 997 -1684 -1680 -8413 -8404 6724 6728 -3242 -3239 2616...
output:
6717.117145739453008
result:
ok found '6717.117145739', expected '6717.117145739', error '0.000000000'
Test #10:
score: -100
Wrong Answer
time: 0ms
memory: 8076kb
input:
1000 1000 -5010 -4999 -2128 -2113 -5798 -5765 705 713 -3956 -3938 -5308 -5307 6759 6772 -772 -770 -860 -859 2308 2323 -5500 -5500 5140 5177 -6747 -6733 7509 7511 8864 8870 -6382 -6374 1901 1904 -5763 -5760 3019 3027 2962 2963 -314 -301 -222 -203 -726 -724 -62 -58 -1203 -1195 -5216 -5215 -4298 -4292 ...
output:
6682581.127471442334354
result:
wrong answer 1st numbers differ - expected: '6682.5811275', found: '6682581.1274714', error = '999.0000000'