QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#661898#5433. Absolute DifferenceHeliumeowWA 6ms21440kbC++206.9kb2024-10-20 18:53:242024-10-20 18:53:25

Judging History

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

  • [2024-10-20 18:53:25]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:21440kb
  • [2024-10-20 18:53:24]
  • 提交

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;

PII a[N],b[N];
int pta,ptb,ptab;
int point[N],tot=0;
int nowa,nowb;
double ans=0;

//find L<=l<=r<=R in a[nowa]
bool checka(int l,int r){
    int 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(int l,int r){
    int 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;
    double 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;
    }
    
    double 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
        int l2=point[i-1],r2=point[i];
        double 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
        int l2=point[i-1],r2=point[i];
        double 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
    double 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";
    double sumT=0,sumST=0;
    int pos=1;
    rep(i,1,n){
        int nowp=a[i].first;
        while(pos<=m){
            int l=b[pos].first,r=b[pos].second;
            if(nowp<l) break;
            if(l<=nowp&&nowp<=r) break;
            double S=-r-l,T=r-l;
            sumT+=T;
            sumST+=S*T;
            pos++;
        }
        int l=b[i].first,r=b[i].second;
        double p=nowp,S=-l-r,T=r-l;
        if(l<=nowp&&nowp<=r){
            double dl=nowp-l,dr=r-nowp;
            // cout<<dl<<" "<<dr<<"\n";
            ans+=(dl*dl+dr*dr)/2;
        }
        ans+=(2*p*sumT+sumST)/2;
    }
    sumT=0,sumST=0;
    pos=m;
    per(i,n,1){
        int nowp=a[i].second;
        while(pos>=1){
            int l=b[pos].first,r=b[pos].second;
            if(nowp>r) break;
            if(l<=nowp&&nowp<=r) break;
            double S=-r-l,T=r-l;
            sumT+=T;
            sumST+=S*T;
            pos--;
        }
        int l=b[i].first,r=b[i].second;
        double p=nowp,S=-l-r,T=r-l;
        // cout<<sumT<<" "<<sumST<<"\n";
        ans+=-(2*p*sumT+sumST)/2;

    }
    ans/=lensuma*lensumb;
}


void work3(){
    //a and b is all point
    double lensuma=n,lensumb=m;
    double 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+=l;
            cnt++;
            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+=l;
            cnt++;
            pos++;
        }
        ans+=nowp*cnt-sum;

    }
    ans/=lensuma*lensumb;


}


void solve(){

    pta=1,ptb=1,ptab=1;

    cin>>n>>m;
    rep(i,1,n){
        cin>>a[i].ft>>a[i].sd;
        pta&=(a[i].ft==a[i].sd);
        point[++tot]=a[i].ft;
        point[++tot]=a[i].sd;

    }
    rep(i,1,m){
        cin>>b[i].ft>>b[i].sd;
        ptb&=(b[i].ft==b[i].sd);
        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;

    if(ptab){
        work3();
    }else if(pta){
        work2();
    }else if(ptb){
        swap(a,b);
        swap(n,m);
        work2();
    }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: 0ms
memory: 8112kb

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: 6ms
memory: 20684kb

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: 8084kb

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: 8068kb

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: 8100kb

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: 4ms
memory: 19824kb

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: 0ms
memory: 21440kb

input:

1 1
-1000000000 1000000000
-999999999 -999999999

output:

999999999.000000000000000

result:

ok found '999999999.000000000', expected '999999999.000000000', error '0.000000000'

Test #8:

score: 0
Accepted
time: 1ms
memory: 8108kb

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: 8136kb

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.117145739449370

result:

ok found '6717.117145739', expected '6717.117145739', error '0.000000000'

Test #10:

score: -100
Wrong Answer
time: 0ms
memory: 19788kb

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.571431246895372

result:

wrong answer 1st numbers differ - expected: '6682.5811275', found: '6682.5714312', error = '0.0000015'