QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#768239#5433. Absolute DifferenceDAleksaWA 1ms3888kbC++142.7kb2024-11-21 05:01:392024-11-21 05:01:39

Judging History

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

  • [2024-11-21 05:01:39]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3888kb
  • [2024-11-21 05:01:39]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const long double eps = 1e-12;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);
    int n, m;
    cin >> n >> m;
    vector<long double> l1(n), r1(n), l2(m), r2(m);
    for(int i = 0; i < n; i++) cin >> l1[i] >> r1[i];
    for(int i = 0; i < m; i++) cin >> l2[i] >> r2[i];
    vector<pair<long double, pair<int, int>>> events;
    for(int i = 0; i < n; i++) {
        events.push_back({l1[i], {1, 0}});
        events.push_back({r1[i] + eps, {-1, 0}});
        events.push_back({l2[i], {1, 1}});
        events.push_back({r2[i] + eps, {-1, 1}});
    }
    sort(events.begin(), events.end());
    vector<pair<long double, long double>> a, b;
    vector<int> cnt(2, 0);
    cnt[events[0].second.second] += events[0].second.first;
    for(int i = 1; i < events.size(); i++) {
        if(events[i - 1].first < events[i].first) {
            if(cnt[0] > 0) a.push_back({events[i - 1].first, events[i].first});
            if(cnt[1] > 0) b.push_back({events[i - 1].first, events[i].first});
        }
        cnt[events[i].second.second] += events[i].second.first;
    }
    for(int i = 0; i < a.size(); i++) cout << a[i].first << " " << a[i].second << "\n";
    for(int i = 0; i < b.size(); i++) cout << b[i].first << " " << b[i].second << "\n";
    long double ans = 0;
    {
        vector<long double> sum(a.size()), prod(a.size());
        sum[0] = a[0].second - a[0].first;
        for(int i = 1; i < a.size(); i++) sum[i] = sum[i - 1] + a[i].second - a[i].first;
        prod[0] = (a[0].second - a[0].first) * 1.0 * (a[0].first + a[0].second) / 2.0;
        for(int i = 1; i < a.size(); i++) prod[i] = prod[i - 1] + (a[i].second - a[i].first) * 1.0 * (a[i].first + a[i].second) / 2.0;
        for(int i = 0; i < b.size(); i++) {
            int j = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
            if(a[j] == b[i]) ans += (a[j].second - a[j].first) * 2.0 * (b[i].second - b[i].first) / 3;
            if(j > 0) {
                ans += (b[i].first + b[i].second) / 2.0 * (b[i].second - b[i].first) * sum[j - 1] - (b[i].second - b[i].first) * prod[j - 1];
            }
            if(j < a.size() - 1) {
                ans += (b[i].first + b[i].second) / 2.0 * (b[i].second - b[i].first) * (sum[a.size() - 1] - sum[j]) - (b[i].second - b[i].first) * (prod[a.size() - 1] - prod[j]);
            }
        }
    }
    long double S = 0, T = 0;
    for(int i = 0; i < a.size(); i++) S += a[i].second - a[i].first;
    for(int i = 0; i < b.size(); i++) T += b[i].second - b[i].first;
    cout << fixed << setprecision(12) << ans / (S * T);
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3888kb

input:

1 1
0 1
0 1

output:

0.000000000000 1.000000000001
0.000000000000 1.000000000001
0.666666666667

result:

wrong answer 1st numbers differ - expected: '0.3333333', found: '0.0000000', error = '0.3333333'