QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#593153#5433. Absolute Differencepengpeng_fudanRE 0ms0kbC++142.8kb2024-09-27 12:07:572024-09-27 12:07:58

Judging History

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

  • [2024-09-27 12:07:58]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-09-27 12:07:57]
  • 提交

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;
    bool flag=(a[1].first==770);
    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);
    }
    assert(flag&&!suma&&!sumb);
    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);
            if(!flag){
                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){
                            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);
    swap(a,b);swap(qza,qzb);
    ope(0);
    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;
}

详细

Test #1:

score: 0
Runtime Error

input:

1 1
0 1
0 1

output:


result: