QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#314723#5144. Set of IntervalsRico64WA 12ms3616kbC++201002b2024-01-26 08:28:322024-01-26 08:28:33

Judging History

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

  • [2024-01-26 08:28:33]
  • 评测
  • 测评结果:WA
  • 用时:12ms
  • 内存:3616kb
  • [2024-01-26 08:28:32]
  • 提交

answer

#include <iostream>
#include <algorithm>

using namespace std;

long long ls[100000], rs[100000];

void solve() {
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> ls[i] >> rs[i];
    }
    int sl[n], sr[n];
    for (int i = 0; i < n; ++i) sl[i] = sr[i] = i;
    sort(sl, sl + n, [](const int& i1, const int& i2) {
        return ls[i1] < ls[i2];
    });
    sort(sr, sr + n, [](const int& i1, const int& i2) {
        return rs[i1] > rs[i2];
    });
    if (n == 1) {
        cout << 1 << endl;
        return;
    }
    long long res = (rs[sr[0]] - ls[sl[0]] + 1) * (rs[sr[0]] - ls[sl[0]]) / 2 - (ls[sl[1]] - ls[sl[0]]) * (ls[sl[1]] - ls[sl[0]] - 1) / 2 - (rs[sr[0]] - rs[sr[1]]) * (rs[sr[0]] - rs[sr[1]] - 1) / 2;
    if (sr[0] == sl[0]) {
        res -= (rs[sr[0]] - rs[sr[1]]) * (ls[sl[1]] - ls[sl[0]]);
    }
    cout << res << endl;
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}

詳細信息

Test #1:

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

input:

4
1
1 1000000000
2
1 1000000000
1 1000000000
4
1 2
3 4
5 6
7 8
4
1 3
2 4
5 8
6 7

output:

1
499999999500000000
26
28

result:

ok 4 number(s): "1 499999999500000000 26 28"

Test #2:

score: 0
Accepted
time: 12ms
memory: 3552kb

input:

10000
1
778216842 910688403
1
513404058 890988011
1
1 1000000000
1
1 1000000000
1
758932694 848837772
1
516433381 715411928
1
1 1000000000
1
1 1000000000
1
1 1000000000
1
1 1000000000
1
1 1000000000
1
652548522 898071173
1
1 1000000000
1
509357508 603420032
1
1 1000000000
1
657294869 887475066
1
1 1...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 10000 numbers

Test #3:

score: -100
Wrong Answer
time: 11ms
memory: 3616kb

input:

10000
2
427286995 863604876
582970459 874563920
2
181948005 565025282
799528580 848659925
2
1 1000000000
716032287 836380611
2
383809946 544540272
520881396 990456979
2
156308569 178412791
731100211 963724967
2
426113388 802990296
556666621 560014605
2
1 1000000000
575838571 811122140
2
255734272 64...

output:

87849603321470913
-8674795744527268
113106465274673025
75195165925255965
-147589701780048260
1256173734724260
207604390726385765
56483863859672889
35036765368929163
36132096841419954
22573394495301601
143688903920213372
166852999281224709
-92803064481147660
63833225117266922
49445284985875548
208118...

result:

wrong answer 2nd numbers differ - expected: '18821102290156188', found: '-8674795744527268'