QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#593430#5433. Absolute Differencepengpeng_fudanWA 1ms4120kbC++142.8kb2024-09-27 14:01:032024-09-27 14:01:03

Judging History

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

  • [2024-09-27 14:01:03]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4120kb
  • [2024-09-27 14:01:03]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll =long long;
void solve(){
    int n,m;
    cin>>n>>m;
    vector<pair<ll,ll>> a(n+1);
    vector<pair<ll,ll>> b(m+1);
    for(int i=1;i<=n;i++)   cin>>a[i].first>>a[i].second;
    for(int i=1;i<=m;i++)   cin>>b[i].first>>b[i].second;
    sort(a.begin()+1,a.end(),[&](pair<ll,ll> a,pair<ll,ll> b){return a.second<b.second;});
    sort(b.begin()+1,b.end(),[&](pair<ll,ll> a,pair<ll,ll> b){return a.second<b.second;});
    vector<__int128_t> qza(n+1),qzb(m+1);
    ll suma=0,sumb=0;
    for(int i=1;i<=n;i++)   suma+=a[i].second-a[i].first;
    for(int i=1;i<=n;i++){
        if(suma==0) qza[i]=1;
        else qza[i]=(a[i].second-a[i].first);
    }

    for(int i=1;i<=m;i++)   sumb+=b[i].second-b[i].first;
    for(int i=1;i<=m;i++){
        if(sumb==0) qzb[i]=1;
        else qzb[i]=(b[i].second-b[i].first);
    }
    if(suma==0)  suma=n;
    if(sumb==0)  sumb=m;
    __int128_t ans=0;
    __int128_t anb=0;
    auto ope=[&](int t)->void {
        __int128_t sb=0,sqzb=0;
        int lo=1;
        for(int i=1;i<(int)a.size();i++){
            while(lo!=(int)b.size()&&b[lo].second<=a[i].first)   {
                sb+=(b[lo].second+b[lo].first)*qzb[lo];
                sqzb+=qzb[lo];
                lo++;
            }
            ans+=-sb*qza[i]+sqzb*qza[i]*(a[i].first+a[i].second);
            int ro=lo;
            while(ro!=(int)b.size()&&(t?b[ro].second<a[i].second:b[ro].second<=a[i].second)){
                auto [x1,x2]=a[i];
                auto [y1,y2]=b[ro];
                if(x1!=x2){
                    if(y1==y2&&y1!=x2){
                        ans+=qzb[ro]*((y1-x1)*(y1-x1)+(x2-y1)*(x2-y1));
                    }
                    else{
                        if(y1<=x1){
                            ans+=((__int128_t)(x1+x2)-(y1+y2))*qza[i]*qzb[ro];
                            anb-=(__int128_t)(x1-y2)*(x1-y2)*(x1-y2);
                        }
                        else{
                            ans+=((__int128_t)(x1+x2)-(y1+y2))*qza[i]*qzb[ro];
                            anb-=(__int128_t)(x1-y2)*(x1-y2)*(x1-y2)-(__int128_t)(x1-y1)*(x1-y1)*(x1-y1);
                        }
                    }
                }
                // cerr<<b[ro].second<<' '<<a[i].second<<' '<<ans<<'\n';
                ro++;
            }
        }
    };
    ope(1);
    // cerr<<(ll)ans<<'\n';
    swap(a,b);swap(qza,qzb);
    ope(0);
    // cerr<<(ll)ans<<'\n';
    // cerr<<(ll)(ans)<<' '<<(ll)(anb)<<' '<<(ll)suma<<' '<<(ll)sumb<<'\n';
    cout<<setprecision(12)<<((long double)(ans*3+anb*2)/((__int128_t)6*suma*sumb))<<'\n';

}
int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

    int _ = 1;
    while (_--) solve();

    return 0;
}


/*                                        
3 1
1 1
2 2
3 3
1 2
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3848kb

input:

1 1
0 1
0 1

output:

0.333333333333

result:

ok found '0.333333333', expected '0.333333333', error '0.000000000'

Test #2:

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

input:

1 1
0 1
1 1

output:

0.5

result:

ok found '0.500000000', expected '0.500000000', error '0.000000000'

Test #3:

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

input:

1 1
-1000000000 1000000000
-1000000000 1000000000

output:

666666666.667

result:

ok found '666666666.667000055', expected '666666666.666666627', error '0.000000000'

Test #4:

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

input:

1 1
-1000000000 0
0 1000000000

output:

1000000000

result:

ok found '1000000000.000000000', expected '1000000000.000000000', error '0.000000000'

Test #5:

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

input:

1 1
-1000000000 -1000000000
-1000000000 1000000000

output:

1000000000

result:

ok found '1000000000.000000000', expected '1000000000.000000000', error '0.000000000'

Test #6:

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

input:

1 1
-999999999 1000000000
-1000000000 -1000000000

output:

1000000000.5

result:

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

Test #7:

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

input:

1 1
-1000000000 1000000000
-999999999 -999999999

output:

999999999

result:

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

Test #8:

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

input:

1 1
1000000000 1000000000
-1000000000 -1000000000

output:

2000000000

result:

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

Test #9:

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

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

result:

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

Test #10:

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

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

result:

ok found '6682.581127470', expected '6682.581127471', error '0.000000000'

Test #11:

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

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

result:

wrong answer 1st numbers differ - expected: '6673.7568169', found: '6673.7562437', error = '0.0000001'