QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#661978 | #5433. Absolute Difference | Heliumeow | WA | 6ms | 10160kb | C++20 | 7.6kb | 2024-10-20 19:39:36 | 2024-10-20 19:39:36 |
Judging History
answer
// #pragma GCC optimize(3)
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("inline")
// #pragma GCC optimize("omit-frame-pointer")
#include<bits/stdc++.h>
// #include<bits/extc++.h>
#define rep(a,b,c) for (int a=b;a<=c;a++)
#define per(a,b,c) for (int a=b;a>=c;a--)
#define repIt(it,ctner) for (auto it=ctner.begin();it!=ctner.end();it++)
#define perIt(it,ctner) for (auto it=ctner.rbegin();it!=ctner.rend();it++)
#define repAdj(i,h,ne,u) for(int i=h[u];i;i=ne[i])
#define setValue(ctner,val) memset(ctner,val,sizeof ctner)
#define output(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n";
#define ft first
#define sd second
using namespace std;
// using namespace __gnu_cxx;
// using namespace __gnu_pbds;
typedef long long LL;
typedef long long ll;
typedef unsigned long long ULL;
typedef unsigned long long ull;
typedef __int128 LLL;
typedef __int128 lll;
typedef long double LD;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
typedef pair<int,LL> PIL;
typedef pair<double,int> PDI;
void LLLread(LLL &x){
x=0;int 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();}
if(f==-1) x=-x;
}
void LLLwrite(LLL x){
if(x<0) putchar('-'),x=-x;
if(x>9) LLLwrite(x/10);
putchar(x%10+'0');
}
//random
LL rnd(const LL &mn = 0, const LL &mx = 100) {
LL x = mn + ((rand()<<15) + rand()) % (mx - mn + 1);
return x;
};
//gcd
LL gcd(LL a,LL b){
return __gcd(a,b);
}
//lcm
LL lcm(LL a,LL b){
return a/__gcd(a,b)*b;
}
int _T=1;
const int N=1e6+5,M=3*N;
const LL mod1=998244353,mod2=1e9+7;
const int imod[4]={39983,39989,39979,39971};
const LL MAXLL=1e18;
const int MAXINT=1e9+1;
const long double pi=acos(-1.0);
const long double eps=1e-10;
//const double phi=(1+sqrt(5))/2;
const string alphabet="abcdefghijklmnopqrstuvwxyz";
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const LL mod=mod1;
void init(){
}
int n,m;
pair<LD,LD> a[N],b[N];
int pta,ptb,ptab;
LD point[N];
int tot=0;
int nowa,nowb;
LD ans=0;
//find L<=l<=r<=R in a[nowa]
bool checka(LD l,LD r){
LD L=a[nowa].ft,R=a[nowa].sd;
if(nowa>n) return 0;
while(R<=l){
nowa++;
if(nowa>n) return 0;
L=a[nowa].ft,R=a[nowa].sd;
}
if(L<=l&&r<=R) return 1;
return 0;
}
bool checkb(LD l,LD r){
LD L=b[nowb].ft,R=b[nowb].sd;
if(nowb>m) return 0;
while(R<=l){
nowb++;
if(nowb>m) return 0;
L=b[nowb].ft,R=b[nowb].sd;
}
if(L<=l&&r<=R) return 1;
return 0;
}
void work1(){
nowa=1,nowb=1;
LD lensuma=0,lensumb=0;
rep(i,1,n){
lensuma+=a[i].sd-a[i].ft;
}
rep(i,1,m){
lensumb+=b[i].sd-b[i].ft;
}
LD sumT=0,sumST=0;
rep(i,2,tot){
//p=r2+l2 q=r2-l2 S=-r1-l1 T=r1-l1
//p q sumT + q sumST
LD l2=point[i-1],r2=point[i];
LD p=r2+l2,q=r2-l2,S=-r2-l2,T=r2-l2;
bool cka=checka(l2,r2),ckb=checkb(l2,r2);
// cout<<l2<<" "<<r2<<" "<<cka<<" "<<ckb<<"\n";
if(cka&&ckb){
ans+=q*q*q/3;
}
if(cka){
ans+=(p*q*sumT+q*sumST)/2;
// cout<<p*q*sumT+q*sumST<<"\n";
}
if(ckb){
sumT+=T;
sumST+=S*T;
}
}
nowa=1,nowb=1;
sumT=0,sumST=0;
rep(i,2,tot){
//p=r2+l2 q=r2-l2 S=-r1-l1 T=r1-l1
//p q sumT + q sumST
LD l2=point[i-1],r2=point[i];
LD p=r2+l2,q=r2-l2,S=-r2-l2,T=r2-l2;
bool cka=checka(l2,r2),ckb=checkb(l2,r2);
// cout<<l2<<" "<<r2<<" "<<cka<<" "<<ckb<<"\n";
if(ckb){
ans+=(p*q*sumT+q*sumST)/2;
// cout<<p*q*sumT+q*sumST<<"\n";
}
if(cka){
sumT+=T;
sumST+=S*T;
}
}
ans/=lensuma*lensumb;
}
void work2(){
//a is all point
LD lensuma=0,lensumb=0;
lensuma=n;
rep(i,1,n){
// cout<<a[i].ft<<" "<<a[i].sd<<"\n";
}
// cout<<"\n";
rep(i,1,m){
lensumb+=b[i].sd-b[i].ft;
// cout<<b[i].ft<<" "<<b[i].sd<<"\n";
}
// cout<<"\n";
LD sumT=0,sumST=0;
int pos=1;
rep(i,1,n){
int nowp=a[i].first;
// cout<<"check point "<<nowp<<"\n";
while(pos<=m){
int l=b[pos].first,r=b[pos].second;
if(nowp<l) break;
if(l<=nowp&&nowp<=r) break;
// cout<<"thorough "<<l<<" "<<r<<"\n";
LD S=-r-l,T=r-l;
sumT+=T;
sumST+=S*T;
pos++;
}
int l=b[pos].first,r=b[pos].second;
LD p=nowp,S=-l-r,T=r-l;
if(l<=nowp&&nowp<=r){
LD dl=nowp-l,dr=r-nowp;
// cout<<dl<<" "<<dr<<"\n";
ans+=(dl*dl+dr*dr)/2;
// cout<<"add pt "<<nowp<<"and "<<l<<" "<<r<<"\n";
}
ans+=(2*p*sumT+sumST)/2;
// cout<<"add pt "<<nowp<<"and previous\n";
}
sumT=0,sumST=0;
pos=m;
per(i,n,1){
int nowp=a[i].second;
// cout<<"check point "<<nowp<<"\n";
while(pos>=1){
int l=b[pos].first,r=b[pos].second;
if(nowp>r) break;
if(l<=nowp&&nowp<=r) break;
// cout<<"thorough "<<l<<" "<<r<<"\n";
LD S=l+r,T=r-l;
sumT+=T;
sumST+=S*T;
pos--;
}
int l=b[pos].first,r=b[pos].second;
LD p=nowp,S=l+r,T=r-l;
// cout<<sumT<<" "<<sumST<<"\n";
ans+=(-2*p*sumT+sumST)/2;
// cout<<"add pt "<<nowp<<"and next\n";
}
ans/=lensuma*lensumb;
}
void work3(){
//a and b is all point
LD lensuma=n,lensumb=m;
LD sum=0,cnt=0;
int pos=1;
rep(i,1,n){
int nowp=a[i].first;
while(pos<=m){
int l=b[pos].first;
if(nowp<l) break;
sum+=(LD)l;
cnt+=1;
pos++;
}
ans+=nowp*cnt-sum;
}
sum=0,cnt=0;
pos=1;
rep(i,1,m){
int nowp=b[i].first;
while(pos<=n){
int l=a[pos].first;
if(nowp<l) break;
sum+=(LD)l;
cnt+=1;
pos++;
}
ans+=nowp*cnt-sum;
}
ans/=lensuma*lensumb;
}
void solve(){
pta=1,ptb=1,ptab=1;
cin>>n>>m;
rep(i,1,n){
int x,y;
cin>>x>>y;
a[i].ft=x,a[i].sd=y;
// pta&=(a[i].ft==a[i].sd);
if(x==y){
a[i].ft-=1e-7;
a[i].sd+=1e-7;
}
point[++tot]=a[i].ft;
point[++tot]=a[i].sd;
}
rep(i,1,m){
int x,y;
cin>>x>>y;
b[i].ft=x,b[i].sd=y;
// ptb&=(b[i].ft==b[i].sd);
if(x==y){
b[i].ft-=1e-7;
b[i].sd+=1e-7;
}
point[++tot]=b[i].ft;
point[++tot]=b[i].sd;
}
ptab=pta&ptb;
sort(a+1,a+n+1);
sort(b+1,b+m+1);
sort(point+1,point+tot+1);
tot=unique(point+1,point+tot+1)-point-1;
work1();
// if(ptab){
// work3();
// }else if(pta){
// work2();
// }else if(ptb){
// swap(a,b);
// swap(n,m);
// work2();
// // if(n==1000&&m==1000){
// // cout<<"half point\n";
// // }
// }else{
// work1();
// }
cout<<fixed<<setprecision(15)<<ans<<"\n";
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
srand(time(0));
init();
// cin>>_T;
rep(i,1,_T){
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 8052kb
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: 0ms
memory: 8104kb
input:
1 1 0 1 1 1
output:
0.500000000000002
result:
ok found '0.500000000', expected '0.500000000', error '0.000000000'
Test #3:
score: 0
Accepted
time: 0ms
memory: 8108kb
input:
1 1 -1000000000 1000000000 -1000000000 1000000000
output:
666666666.666666666686069
result:
ok found '666666666.666666627', expected '666666666.666666627', error '0.000000000'
Test #4:
score: 0
Accepted
time: 0ms
memory: 8104kb
input:
1 1 -1000000000 0 0 1000000000
output:
1000000000.000000000000000
result:
ok found '1000000000.000000000', expected '1000000000.000000000', error '0.000000000'
Test #5:
score: 0
Accepted
time: 1ms
memory: 8140kb
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: 8120kb
input:
1 1 -999999999 1000000000 -1000000000 -1000000000
output:
1000000000.500000000000000
result:
ok found '1000000000.500000000', expected '1000000000.500000000', error '0.000000000'
Test #7:
score: 0
Accepted
time: 1ms
memory: 8100kb
input:
1 1 -1000000000 1000000000 -999999999 -999999999
output:
999999999.000000000523869
result:
ok found '999999999.000000000', 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: 2ms
memory: 8124kb
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.117145608800719
result:
ok found '6717.117145609', expected '6717.117145739', error '0.000000000'
Test #10:
score: 0
Accepted
time: 0ms
memory: 10160kb
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:
6682.581128579409868
result:
ok found '6682.581128579', expected '6682.581127471', error '0.000000000'
Test #11:
score: 0
Accepted
time: 0ms
memory: 8184kb
input:
1000 1000 770 770 5869 5869 -8786 -8786 7549 7549 -4165 -4165 4023 4023 -9779 -9779 7797 7797 1105 1105 508 508 7653 7653 -359 -359 9393 9393 -9363 -9363 -4160 -4160 -3682 -3682 9409 9409 -8548 -8548 -9908 -9908 -7494 -7494 3751 3751 2326 2326 -3311 -3311 3651 3651 -7663 -7663 5376 5376 -7071 -7071 ...
output:
6673.756817906854251
result:
ok found '6673.756817907', expected '6673.756816891', error '0.000000000'
Test #12:
score: 0
Accepted
time: 0ms
memory: 7972kb
input:
1000 1000 -735 -735 -829 -829 -6376 -6376 8558 8558 155 155 5533 5533 8800 8800 -1738 -1738 919 919 52 52 2076 2076 -6911 -6911 139 139 6733 6733 9923 9923 -4619 -4619 -9429 -9429 9902 9902 -5984 -5984 2580 2580 8738 8738 7960 7960 3388 3388 -2689 -2689 7986 7986 2565 2565 -8908 -8908 9359 9359 -434...
output:
6479.384681817152881
result:
ok found '6479.384681817', expected '6479.384680000', error '0.000000000'
Test #13:
score: 0
Accepted
time: 6ms
memory: 8364kb
input:
100 10000 82274 82408 61583 61902 -54304 -54007 -48488 -48316 -92517 -91939 85001 85160 33086 33374 36458 36573 -15785 -11838 93971 94863 50496 53064 -68609 -68302 -91873 -91176 -96937 -96753 9481 9976 83600 83691 17742 18693 55685 56039 56323 57845 88761 90277 22886 23642 30848 31047 -34662 -33470 ...
output:
65016.298634190719756
result:
ok found '65016.298634191', expected '65016.298634798', error '0.000000000'
Test #14:
score: -100
Wrong Answer
time: 6ms
memory: 8420kb
input:
100 10000 -89227 -88897 -70959 -68913 -60233 -59597 81753 81820 96806 97104 -58324 -57553 -38857 -37087 -81344 -81311 22701 22890 -68517 -66298 -19753 -19047 -80409 -79437 6355 7569 -13999 -12586 -84981 -82448 -29865 -29624 -76088 -75272 70697 72265 85493 86097 82574 84418 -8937 -8079 -92387 -90609 ...
output:
65683.869778813758266
result:
wrong answer 1st numbers differ - expected: '65683.8697071', found: '65683.8697788', error = '0.0000000'