#include <bits/stdc++.h>
#define int long long
#define endl "\n"
using namespace std;
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n, a, b;
cin >> n >> a >> b;
long double k1 = a * (long double) b;
int k = (int) 1e18 + 1;
if (k1 <= 1e18) {
k = a * b;
}
vector<pair<int, int>> segs;
for (int i = 0; i < n; i++) {
int l, r;
cin >> l >> r;
if (r - l + 1 >= k) {
segs.emplace_back(0, k - 1);
continue;
}
int l1 = l % k, r1 = r % k;
if (r1 < l1) {
segs.emplace_back(0, r1);
segs.emplace_back(l1, k - 1);
} else {
segs.emplace_back(l1, r1);
}
}
sort(segs.begin(), segs.end());
int mxr = -1;
int res = 0;
for (auto x : segs) {
res += max(x.second - max(mxr, x.first - 1), 0LL);
mxr = max(x.second, mxr);
}
cout << res << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
10 ms |
768 KB |
Output is correct |
3 |
Correct |
9 ms |
768 KB |
Output is correct |
4 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
357 ms |
16852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
499 ms |
16852 KB |
Output is correct |
3 |
Incorrect |
524 ms |
16852 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
499 ms |
16852 KB |
Output is correct |
3 |
Incorrect |
524 ms |
16852 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
499 ms |
16852 KB |
Output is correct |
3 |
Incorrect |
524 ms |
16852 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
65 ms |
2544 KB |
Output is correct |
3 |
Correct |
58 ms |
2544 KB |
Output is correct |
4 |
Correct |
594 ms |
16852 KB |
Output is correct |
5 |
Correct |
59 ms |
2680 KB |
Output is correct |
6 |
Correct |
58 ms |
2544 KB |
Output is correct |
7 |
Correct |
56 ms |
2544 KB |
Output is correct |
8 |
Correct |
59 ms |
2544 KB |
Output is correct |
9 |
Correct |
59 ms |
2544 KB |
Output is correct |
10 |
Correct |
59 ms |
2544 KB |
Output is correct |
11 |
Correct |
62 ms |
2540 KB |
Output is correct |
12 |
Correct |
51 ms |
2544 KB |
Output is correct |
13 |
Correct |
57 ms |
2552 KB |
Output is correct |
14 |
Correct |
560 ms |
16852 KB |
Output is correct |
15 |
Incorrect |
58 ms |
2552 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
10 ms |
768 KB |
Output is correct |
3 |
Correct |
9 ms |
768 KB |
Output is correct |
4 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |