QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#768244#5433. Absolute DifferenceDAleksaWA 0ms3908kbC++142.8kb2024-11-21 05:17:202024-11-21 05:17:21

Judging History

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

  • [2024-11-21 05:17:21]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3908kb
  • [2024-11-21 05:17:20]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const long double eps = 1e-10;

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());
//    for(int i = 0; i < events.size(); i++) cout << events[i].first << " ";
//    cout << "\n";
    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";
//    cout << "\n";
//    for(int i = 0; i < b.size(); i++) cout << b[i].first << " " << b[i].second << "\n";
//    return 0;
    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) * (b[i].second - b[i].first) * (b[i].second - b[i].first) / 3.0;
            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: 100
Accepted
time: 0ms
memory: 3904kb

input:

1 1
0 1
0 1

output:

0.333333333367

result:

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

Test #2:

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

input:

1 1
0 1
1 1

output:

0.500000000000

result:

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

Test #3:

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

input:

1 1
-1000000000 1000000000
-1000000000 1000000000

output:

666666666.666666666744

result:

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

Test #4:

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

input:

1 1
-1000000000 0
0 1000000000

output:

999999999.999999999942

result:

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

Test #5:

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

input:

1 1
-1000000000 -1000000000
-1000000000 1000000000

output:

1000000000.000000000000

result:

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

Test #6:

score: -100
Wrong Answer
time: 0ms
memory: 3792kb

input:

1 1
-999999999 1000000000
-1000000000 -1000000000

output:

0.000000000000

result:

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