QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#764206#5433. Absolute DifferencefosovRE 0ms3988kbC++142.9kb2024-11-20 06:44:372024-11-20 06:44:39

Judging History

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

  • [2024-11-20 06:44:39]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3988kb
  • [2024-11-20 06:44:37]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define ll long long 
#define lll __int128
#define INF 0x3f3f3f3f
#define LNF 0x3f3f3f3f3f3f3f3fll
#define MOD 998244353
#define pii pair<int, int>
#define ld long double
#define fi first
#define se second
#define all(a) a.begin(), a.end()

#define N 20

int main() {
#ifdef TEST
    freopen("zz.in", "r+", stdin);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout << setprecision(18);

    int n, m; cin >> n >> m;

    vector<pii> a(n), b(m);
    ll ca = 0, cb = 0;
    for (int i = 0; i < n; ++ i) cin >> a[i].fi >> a[i].se, ca += a[i].se - a[i].fi;
    for (int i = 0; i < m; ++ i) cin >> b[i].fi >> b[i].se, cb += b[i].se - b[i].fi;
    sort(all(a)), sort(all(b));

    auto pa = [&](pii x) {
        return ca ? 1.0L * (x.se - x.fi) / ca : 1.0L / n;
    };
    auto pb = [&](pii x) {
        return cb ? 1.0L * (x.se - x.fi) / cb : 1.0L / m;
    };
    auto w = [&](pii x) {
        return 1.0L * x.fi + 1.0L * (x.se - x.fi) / 2.0L;
    };

    vector<ld> sp(m+1, 0.0L), swp(m+1, 0.0L);
    for (int i = 0; i < m; ++ i) {
        sp[i+1] = sp[i] + pb(b[i]);
        swp[i+1] = swp[i] + w(b[i]) * pb(b[i]);
    }

    ld res = 0;
    for (int i = 0, l = 0, r = 0; i < n; ++ i) {
        while (l < n && b[l].se <= a[i].fi) ++ l;
        while (r < n && b[r].fi < a[i].se) ++ r;
        
        res += (w(a[i]) * sp[l] - swp[l]) * pa(a[i]);
        res += ((swp[m] - swp[r]) - w(a[i]) * (sp[m] - sp[r])) * pa(a[i]);

        queue<pair<pii, pii>> cur;
        for (int j = l; j < r; ++ j) cur.emplace(a[i], b[j]);
        while (!cur.empty()) {
            auto [u, v] = cur.front(); cur.pop();

            if (u.fi == v.fi && u.se == v.se) {
                res += 1.0L / 3 * (u.se - u.fi) * pa(u) * pb(v);
                continue;
            }
            if (u.fi <= v.fi && v.se <= u.se && v.fi != v.se) {
                cur.emplace(pii(u.fi, v.fi), v);
                cur.emplace(v, v);
                cur.emplace(pii(v.se, u.se), v);
                continue;
            }
            if (v.fi < u.fi && v.se > u.fi) {
                cur.emplace(u, pii(v.fi, u.fi));
                cur.emplace(u, pii(u.fi, v.se));
                continue;
            }
            if (v.se > u.se && v.fi < u.se) {
                cur.emplace(u, pii(u.se, v.se));
                cur.emplace(u, pii(v.fi, u.se));
                continue;
            }
            assert(max(u.fi, v.fi) == min(u.se, v.se));
            if (v.fi <= u.fi) {
                res += (w(u) - w(v)) * pa(u) * pb(v);
                continue;
            }
            if (v.se >= u.se) {
                res += (w(v) - w(u)) * pa(u) * pb(v); 
                continue;
            }
            assert(0);
        }
    }

    cout << res << '\n';
}   

// = (p0w0/q0) * p1/q1 - (p1w1/q1) * (p0/q0)

// = (w0 - w1) * p1 * p0
// = w0 p1 - w1 p1

詳細信息

Test #1:

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

input:

1 1
0 1
0 1

output:

0.333333333333333333

result:

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

Test #2:

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

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

input:

1 1
-1000000000 1000000000
-1000000000 1000000000

output:

666666666.666666667

result:

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

Test #4:

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

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

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

input:

1 1
-999999999 1000000000
-1000000000 -1000000000

output:

1000000000.5

result:

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

Test #7:

score: -100
Runtime Error

input:

1 1
-1000000000 1000000000
-999999999 -999999999

output:


result: