#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MN = 1e5 + 5;
using ull = unsigned long long;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
ull n, a, b; cin >> n >> a >> b;
ull p = a / __gcd(a, b + 1) * b;
vector<pair<ull, ull>> v;
for (int i = 0; i < n; i++) {
ull l, r; cin >> l >> r;
l %= p, r %= p;
if (l > r) v.emplace_back(0, r), v.emplace_back(l, p - 1);
else v.emplace_back(l, r);
}
v.emplace_back(p, p);
sort(all(v));
ull ans = 0;
for (int i = 0; i < v.size();) {
int j = i;
for (; v[i].second >= v[j].second && j < v.size(); j++);
ans += v[i].second - v[i].first + 1;
v[j].first = max(v[j].first, v[i].second + 1);
i = j;
}
cout << ans - 1 << '\n';
return 0;
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:14:23: warning: comparison of integer expressions of different signedness: 'int' and 'ull' {aka 'long long unsigned int'} [-Wsign-compare]
14 | for (int i = 0; i < n; i++) {
| ~~^~~
strange_device.cpp:23:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long unsigned int, long long unsigned int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | for (int i = 0; i < v.size();) {
| ~~^~~~~~~~~~
strange_device.cpp:25:48: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long unsigned int, long long unsigned int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for (; v[i].second >= v[j].second && j < v.size(); j++);
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
6 ms |
748 KB |
Output is correct |
3 |
Correct |
6 ms |
748 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
0 ms |
364 KB |
Output is correct |
11 |
Correct |
0 ms |
364 KB |
Output is correct |
12 |
Correct |
0 ms |
364 KB |
Output is correct |
13 |
Correct |
0 ms |
364 KB |
Output is correct |
14 |
Correct |
0 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
6 ms |
748 KB |
Output is correct |
17 |
Correct |
59 ms |
2536 KB |
Output is correct |
18 |
Correct |
0 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
414 ms |
17016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
549 ms |
16976 KB |
Output is correct |
3 |
Correct |
571 ms |
16976 KB |
Output is correct |
4 |
Correct |
543 ms |
17016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
549 ms |
16976 KB |
Output is correct |
3 |
Correct |
571 ms |
16976 KB |
Output is correct |
4 |
Correct |
543 ms |
17016 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
530 ms |
16848 KB |
Output is correct |
7 |
Correct |
566 ms |
17000 KB |
Output is correct |
8 |
Correct |
541 ms |
16848 KB |
Output is correct |
9 |
Correct |
579 ms |
16848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
549 ms |
16976 KB |
Output is correct |
3 |
Correct |
571 ms |
16976 KB |
Output is correct |
4 |
Correct |
543 ms |
17016 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
53 ms |
2536 KB |
Output is correct |
7 |
Correct |
55 ms |
2536 KB |
Output is correct |
8 |
Correct |
53 ms |
2536 KB |
Output is correct |
9 |
Correct |
52 ms |
2536 KB |
Output is correct |
10 |
Correct |
52 ms |
2536 KB |
Output is correct |
11 |
Correct |
55 ms |
2536 KB |
Output is correct |
12 |
Correct |
53 ms |
2536 KB |
Output is correct |
13 |
Correct |
56 ms |
2536 KB |
Output is correct |
14 |
Correct |
53 ms |
2536 KB |
Output is correct |
15 |
Correct |
58 ms |
2536 KB |
Output is correct |
16 |
Correct |
57 ms |
2536 KB |
Output is correct |
17 |
Correct |
52 ms |
2536 KB |
Output is correct |
18 |
Correct |
554 ms |
17020 KB |
Output is correct |
19 |
Correct |
549 ms |
17008 KB |
Output is correct |
20 |
Correct |
583 ms |
16848 KB |
Output is correct |
21 |
Correct |
57 ms |
2536 KB |
Output is correct |
22 |
Correct |
50 ms |
2536 KB |
Output is correct |
23 |
Correct |
169 ms |
8668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
61 ms |
2536 KB |
Output is correct |
3 |
Correct |
56 ms |
2536 KB |
Output is correct |
4 |
Correct |
610 ms |
16848 KB |
Output is correct |
5 |
Correct |
56 ms |
2536 KB |
Output is correct |
6 |
Correct |
59 ms |
2536 KB |
Output is correct |
7 |
Correct |
56 ms |
2536 KB |
Output is correct |
8 |
Correct |
57 ms |
2536 KB |
Output is correct |
9 |
Correct |
57 ms |
2536 KB |
Output is correct |
10 |
Correct |
56 ms |
2536 KB |
Output is correct |
11 |
Correct |
58 ms |
2536 KB |
Output is correct |
12 |
Correct |
60 ms |
2536 KB |
Output is correct |
13 |
Correct |
56 ms |
2536 KB |
Output is correct |
14 |
Correct |
582 ms |
16848 KB |
Output is correct |
15 |
Correct |
55 ms |
2536 KB |
Output is correct |
16 |
Correct |
536 ms |
17160 KB |
Output is correct |
17 |
Correct |
539 ms |
17024 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
6 ms |
748 KB |
Output is correct |
3 |
Correct |
6 ms |
748 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
0 ms |
364 KB |
Output is correct |
11 |
Correct |
0 ms |
364 KB |
Output is correct |
12 |
Correct |
0 ms |
364 KB |
Output is correct |
13 |
Correct |
0 ms |
364 KB |
Output is correct |
14 |
Correct |
0 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
6 ms |
748 KB |
Output is correct |
17 |
Correct |
59 ms |
2536 KB |
Output is correct |
18 |
Correct |
0 ms |
364 KB |
Output is correct |
19 |
Correct |
0 ms |
364 KB |
Output is correct |
20 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |