QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#204029#5433. Absolute Differenceucup-team870WA 2ms8148kbC++203.4kb2023-10-07 00:14:012023-10-07 00:14:02

Judging History

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

  • [2023-10-07 00:14:02]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:8148kb
  • [2023-10-07 00:14:01]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i=j;i<=k;++i)
#define per(i,j,k) for(int i=j;i>=k;--i)
#define IOS {cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);}
#define int long long
#define ll long long
#define P pair<int,int>
#define vi vector<int>
#define double long double
#define db double
const int N=1e5+5,inf=1e9+7;
int n,m,fl;
P a[N],b[N];
db s1[N],s2[N],mi; //len,mid*len
db lb[N];
db f1(int l1,int r1,int l2,int r2){  //l1>r2
    return ((l1+r1)/2.0-(l2+r2)/2.0)*(r1-l1)*(r2-l2);
}
db p3(db x){return x*x*x/3;}
db cal(int i,int j){
    if(fl){
        db l1=a[i].first,r1=a[i].second,l2=b[j].first;
        return (l2-l1)*(-l1+l2)/2+(r1-l2)*(r1-l2)/2;
    }
    db res=0;
    P ta=a[i],tb=b[j];
    if(ta.first<tb.first)swap(ta,tb);
    if(tb.second<ta.second){
        res+=f1(ta.first,ta.second,tb.first,ta.first);
        res+=f1(tb.second,ta.second,ta.first,tb.second);
        res+=p3(tb.second-ta.first);
    }
    else{
        res=f1(ta.first,ta.second,tb.first,ta.first)+f1(ta.second,tb.second,ta.first,ta.second)+p3(ta.second-ta.first);
    }
    return res;
}
bool crs(int i,int j){
    return (!(b[j].second<=a[i].first)) && (!(b[j].first>=a[i].second));
}
signed main(){
    IOS
    cout<<fixed<<setprecision(15);
    // cout<<2e9/3<<endl;
    cin>>n>>m;
    ll sa=0,sb=0;
    rep(i,1,n){
        cin>>a[i].first>>a[i].second; sa+=a[i].second-a[i].first;
    }
    rep(i,1,m){
        cin>>b[i].first>>b[i].second; sb+=b[i].second-b[i].first;
    }
    b[m+1].first=inf; b[0]={-inf,-inf};
    if(sa==0 && sb==0){
        rep(i,1,m)s2[i]=s2[i-1]+b[i].first;
        int L=0; db ans=0;
        sort(a+1,a+n+1); sort(b+1,b+m+1);
        rep(i,1,n){
            while(b[L+1].first<=a[i].first)++L;
            ans+=1ll*a[i].first*L-s2[L] + s2[m]-s2[L]-1ll*a[i].first*(m-L);
        }
        cout<<ans/(1.0*n*m);
        return 0;
    }
    if(sa==0){
        swap(n,m); swap(a,b); swap(sa,sb); 
    }
    sort(a+1,a+n+1); sort(b+1,b+m+1);
    if(sb!=0){
        rep(i,1,m)lb[i]=b[i].second-b[i].first;
    }
    else{
        sb=m; fl=1;
        rep(i,1,m)lb[i]=1;
    }
    rep(i,1,m){
        s1[i]=s1[i-1]+lb[i];
        s2[i]=s2[i-1]+lb[i]*(b[i].second+b[i].first+0.0)/2;
    }
    int L=0;
    db res=0;
    b[m+1].first=inf; b[0]={-inf,-inf};
    // cout<<n<<endl;
    // rep(i,1,n)cout<<a[i].first<<" "<<a[i].second<<endl;
    // rep(i,1,m)cout<<b[i].first<<" "<<b[i].second<<endl;
    rep(i,1,n){
        while(b[L+1].first<=a[i].first)++L;
        // cout<<L<<endl;
        int l;
        if(crs(i,L))l=L; else l=L+1;
        int r=l-1;
        while( crs(i,r+1) )++r;
        // cout<<l<<" "<<r<<endl; 
        // cout<<s2[m]-s2[r]<<" "<<s1[m]-s1[r]<<endl;
        mi=(a[i].first+a[i].second)/2.0;
        res+=( mi*s1[l-1] - s2[l-1])*(a[i].second-a[i].first);
        res+=(s2[m]-s2[r]- mi*(s1[m]-s1[r]) ) *(a[i].second-a[i].first);
        // cout<<res<<endl;
        rep(j,l,r)res+=cal(i,j);
        // cout<<res<<endl;
    }
    // cout<<res<<endl;
    cout<<res/(1.0*sa*sb);
}
/*
4 4
1 1
3 3 
7 7
9 9
0 2
2 5
6 8
10 11

144/32 != 147/32

3 1
5 5
9 9
7 7 
1 10

4 4
1 1
7 7 
3 3
9 9
3 3
4 4
7 7
8 8

2 3
3 6
7 9
1 4
5 8
9 10
2.771428

1 1
0 2
1 1

2 2
3 6
7 7
1 4
5 7

2 2
0 1
2 4
1 1
3 3
13/6

4 3
1 1
2 2
3 3
4 4
1 1
3 3
5 5
1.6666667

*/

详细

Test #1:

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

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: 1ms
memory: 7992kb

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

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: 1ms
memory: 5948kb

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

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

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

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

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

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

result:

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

Test #10:

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

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

result:

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

Test #11:

score: 0
Accepted
time: 2ms
memory: 7708kb

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

result:

ok found '6673.756816891', expected '6673.756816891', error '0.000000000'

Test #12:

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

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:

3539.146866000000000

result:

wrong answer 1st numbers differ - expected: '6479.3846800', found: '3539.1468660', error = '0.4537835'