QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#661882#5433. Absolute DifferenceHeliumeowWA 4ms20628kbC++206.4kb2024-10-20 18:44:542024-10-20 18:44:55

Judging History

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

  • [2024-10-20 18:44:55]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:20628kb
  • [2024-10-20 18:44:54]
  • 提交

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;



}


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

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

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

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

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

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

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

input:

1 1
-1000000000 1000000000
-999999999 -999999999

output:

999999999.000000000000000

result:

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

Test #8:

score: -100
Wrong Answer
time: 1ms
memory: 8116kb

input:

1 1
1000000000 1000000000
-1000000000 -1000000000

output:

0.000000000000000

result:

wrong answer 1st numbers differ - expected: '2000000000.0000000', found: '0.0000000', error = '1.0000000'