QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#417405#5433. Absolute DifferenceocharinWA 1ms3932kbC++232.9kb2024-05-22 18:23:402024-05-22 18:23:41

Judging History

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

  • [2024-05-22 18:23:41]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3932kb
  • [2024-05-22 18:23:40]
  • 提交

answer

/*

                                _/                                      _/
       _/_/        _/_/_/      _/_/_/        _/_/_/      _/  _/_/               _/_/_/
    _/    _/    _/            _/    _/    _/    _/      _/_/          _/       _/    _/
   _/    _/    _/            _/    _/    _/    _/      _/            _/       _/    _/
    _/_/        _/_/_/      _/    _/      _/_/_/      _/            _/       _/    _/

*/
#include<bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int inf=1e18;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin>>n>>m;
    vector<array<int,2>>a(n),b(m);
    int ans1=0,ans2=0;
    for(auto &[x,y]:a) cin>>x>>y,ans1+=y-x;
    for(auto &[x,y]:b) cin>>x>>y,ans2+=y-x;
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    if(!ans1) ans1=1;
    if(!ans2) ans2=1;
    double res=0;
    auto cal1=[&]()->void{
        int j=0;
        double c0=0,c1=0,c2=0,cc0=0;
        for(int i=0;i<a.size();++i){
            while(j<b.size() && b[j][1]<=a[i][0]){
                if(b[j][0]==b[j][1]) c0+=b[j][0],cc0+=1;
                else{
                    c1+=b[j][1]-b[j][0];
                    c2+=b[j][1]*b[j][1]-b[j][0]*b[j][0];
                }
                j++;
            }
            if(a[i][0]==a[i][1]) res+=cc0*a[i][0]-c0+a[i][0]*c1-c2*1l/2;
            else{
                res+=(a[i][1]*a[i][1]-a[i][0]*a[i][0])*1l/2*cc0;
                res+=(a[i][1]*a[i][1]-a[i][0]*a[i][0])*1l/2*c1;
                res-=(a[i][1]-a[i][0])*(c0+c2*1l/2);
            }
        }
    };
    cal1();
    swap(a,b);
    cal1();
    swap(a,b);
    vector<array<int,2>>c;
    for(int i=0;i<n;++i){
        int x=lower_bound(b.begin(),b.end(),a[i])-b.begin();
        if(x){
            if(b[x-1][1]>a[i][0]) c.push_back({i,x-1});
        }
        while(x<m && b[x][0]<a[i][1]){
            c.push_back({i,x});
            x++;
        }
    }
    auto cal2=[&](array<int,2>a,array<int,2>b)->void{
        if(a>b) swap(a,b);
        double l1=a[0],r1=a[1],l2=b[0],r2=b[1];

        if(a[0]!=a[1] && b[0]!=b[1]){
            if(l1<l2) res+=(l2-l1)*0.5l*(r2*r2-l2*l2)-(r2-l2)*0.5l*(l2*l2-l1*l1);
            if(r2<r1) res+=(r2-l2)*0.5l*(r1*r1-r2*r2)-(r1-r2)*0.5l*(r2*r2-l2*l2);
            if(r2<=r1) res+=r2*1l*r2*r2/3-l2*1l*l2*l2/3-(l2+r2)*1l/2*(r2*r2-l2*l2)+(r2-l2)*1l/2*(r2*r2+l2*l2);
            if(r2>r1) res+=r1*1l*r1*r1/3-l2*1l*l2*l2/3-(l2+r2)*1l/2*(r1*r1-l2*l2)+(r1-l2)*1l/2*(r2*r2+l2*l2);
        }
        else if(a[0]==a[1] && b[0]==b[1]) res+=abs(l2-l1);
        else{
            if(b[0]==b[1]) swap(l1,l2),swap(r1,r2);
            double c=l1;
            res+=c*c-c*(l2+r2)+(l2*l2+r2*r2)*1l/2;
        }
    };
    for(auto [x,y]:c) cal2(a[x],b[y]);
    cout<<fixed<<setprecision(15)<<res/ans1/ans2<<"\n";
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3748kb

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

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

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

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

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

input:

1 1
-999999999 1000000000
-1000000000 -1000000000

output:

1000000000.499999999767169

result:

ok found '1000000000.500000000', expected '1000000000.500000000', error '0.000000000'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3720kb

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

input:

1 1
1000000000 1000000000
-1000000000 -1000000000

output:

2000000000.000000000000000

result:

ok found '2000000000.000000000', expected '2000000000.000000000', error '0.000000000'

Test #9:

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

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:

6790.041141059675288

result:

wrong answer 1st numbers differ - expected: '6717.1171457', found: '6790.0411411', error = '0.0108564'