#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n;
ll A, B;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout << fixed << setprecision(11);
cerr << fixed << setprecision(6);
cin >> n >> A >> B;
A /= __gcd(A, B + 1);
ll mod = 1e18 + 1;
if (A <= (LLONG_MAX / 2) / B) mod = A * B;
vector<pair<ll, ll>> vec;
for (int i = 0; i < n; ++i) {
ll l, r;
cin >> l >> r;
ll len = r - l + 1;
if (len >= mod) {
cout << mod << "\n";
return 0;
}
l = l % mod;
r = r % mod;
if (l <= r) {
vec.push_back({l, r});
} else {
vec.push_back({l, mod - 1});
vec.push_back({0, r});
}
}
vector<pair<ll, int>> Events;
for (int i = 0; i < vec.size(); ++i) {
Events.push_back({vec[i].first, 0});
Events.push_back({vec[i].second, 1});
}
sort(Events.begin(), Events.end());
int bal = 0;
ll left = 0, tot = 0;
for (auto ev : Events) {
if (ev.second == 0) {
bal++;
if (bal == 1) left = ev.first;
} else {
bal--;
if (bal == 0) tot += ev.first - left + 1;
}
}
cout << tot << "\n";
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:40:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | for (int i = 0; i < vec.size(); ++i) {
| ~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
308 KB |
Output is correct |
2 |
Correct |
5 ms |
1464 KB |
Output is correct |
3 |
Correct |
5 ms |
1484 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
312 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
320 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
312 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
312 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
6 ms |
1476 KB |
Output is correct |
17 |
Correct |
57 ms |
9764 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
316 KB |
Output is correct |
5 |
Correct |
0 ms |
312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
355 ms |
74172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
517 ms |
85964 KB |
Output is correct |
3 |
Correct |
538 ms |
86116 KB |
Output is correct |
4 |
Correct |
497 ms |
86072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
517 ms |
85964 KB |
Output is correct |
3 |
Correct |
538 ms |
86116 KB |
Output is correct |
4 |
Correct |
497 ms |
86072 KB |
Output is correct |
5 |
Correct |
0 ms |
312 KB |
Output is correct |
6 |
Correct |
523 ms |
86196 KB |
Output is correct |
7 |
Correct |
499 ms |
86092 KB |
Output is correct |
8 |
Correct |
506 ms |
86004 KB |
Output is correct |
9 |
Correct |
589 ms |
86024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
517 ms |
85964 KB |
Output is correct |
3 |
Correct |
538 ms |
86116 KB |
Output is correct |
4 |
Correct |
497 ms |
86072 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
48 ms |
9792 KB |
Output is correct |
7 |
Correct |
52 ms |
9796 KB |
Output is correct |
8 |
Correct |
52 ms |
9832 KB |
Output is correct |
9 |
Correct |
49 ms |
9768 KB |
Output is correct |
10 |
Correct |
48 ms |
9804 KB |
Output is correct |
11 |
Correct |
49 ms |
9712 KB |
Output is correct |
12 |
Correct |
47 ms |
9788 KB |
Output is correct |
13 |
Correct |
51 ms |
9788 KB |
Output is correct |
14 |
Correct |
51 ms |
9708 KB |
Output is correct |
15 |
Correct |
53 ms |
9804 KB |
Output is correct |
16 |
Correct |
53 ms |
9752 KB |
Output is correct |
17 |
Correct |
52 ms |
9796 KB |
Output is correct |
18 |
Correct |
517 ms |
86220 KB |
Output is correct |
19 |
Correct |
507 ms |
86056 KB |
Output is correct |
20 |
Correct |
602 ms |
86128 KB |
Output is correct |
21 |
Correct |
58 ms |
9828 KB |
Output is correct |
22 |
Correct |
44 ms |
9724 KB |
Output is correct |
23 |
Correct |
147 ms |
34956 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
52 ms |
9772 KB |
Output is correct |
3 |
Correct |
53 ms |
9788 KB |
Output is correct |
4 |
Correct |
621 ms |
86160 KB |
Output is correct |
5 |
Correct |
54 ms |
9796 KB |
Output is correct |
6 |
Correct |
54 ms |
9792 KB |
Output is correct |
7 |
Correct |
54 ms |
9736 KB |
Output is correct |
8 |
Correct |
56 ms |
9736 KB |
Output is correct |
9 |
Correct |
64 ms |
9820 KB |
Output is correct |
10 |
Correct |
56 ms |
9760 KB |
Output is correct |
11 |
Correct |
52 ms |
9816 KB |
Output is correct |
12 |
Correct |
48 ms |
9728 KB |
Output is correct |
13 |
Correct |
56 ms |
9796 KB |
Output is correct |
14 |
Correct |
587 ms |
85900 KB |
Output is correct |
15 |
Correct |
56 ms |
9724 KB |
Output is correct |
16 |
Correct |
495 ms |
86224 KB |
Output is correct |
17 |
Correct |
510 ms |
86008 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
308 KB |
Output is correct |
2 |
Correct |
5 ms |
1464 KB |
Output is correct |
3 |
Correct |
5 ms |
1484 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
312 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
320 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
312 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
312 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
6 ms |
1476 KB |
Output is correct |
17 |
Correct |
57 ms |
9764 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
316 KB |
Output is correct |
23 |
Correct |
0 ms |
312 KB |
Output is correct |
24 |
Correct |
0 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
355 ms |
74172 KB |
Output is correct |
29 |
Correct |
0 ms |
204 KB |
Output is correct |
30 |
Correct |
517 ms |
85964 KB |
Output is correct |
31 |
Correct |
538 ms |
86116 KB |
Output is correct |
32 |
Correct |
497 ms |
86072 KB |
Output is correct |
33 |
Correct |
0 ms |
312 KB |
Output is correct |
34 |
Correct |
523 ms |
86196 KB |
Output is correct |
35 |
Correct |
499 ms |
86092 KB |
Output is correct |
36 |
Correct |
506 ms |
86004 KB |
Output is correct |
37 |
Correct |
589 ms |
86024 KB |
Output is correct |
38 |
Correct |
0 ms |
204 KB |
Output is correct |
39 |
Correct |
48 ms |
9792 KB |
Output is correct |
40 |
Correct |
52 ms |
9796 KB |
Output is correct |
41 |
Correct |
52 ms |
9832 KB |
Output is correct |
42 |
Correct |
49 ms |
9768 KB |
Output is correct |
43 |
Correct |
48 ms |
9804 KB |
Output is correct |
44 |
Correct |
49 ms |
9712 KB |
Output is correct |
45 |
Correct |
47 ms |
9788 KB |
Output is correct |
46 |
Correct |
51 ms |
9788 KB |
Output is correct |
47 |
Correct |
51 ms |
9708 KB |
Output is correct |
48 |
Correct |
53 ms |
9804 KB |
Output is correct |
49 |
Correct |
53 ms |
9752 KB |
Output is correct |
50 |
Correct |
52 ms |
9796 KB |
Output is correct |
51 |
Correct |
517 ms |
86220 KB |
Output is correct |
52 |
Correct |
507 ms |
86056 KB |
Output is correct |
53 |
Correct |
602 ms |
86128 KB |
Output is correct |
54 |
Correct |
58 ms |
9828 KB |
Output is correct |
55 |
Correct |
44 ms |
9724 KB |
Output is correct |
56 |
Correct |
147 ms |
34956 KB |
Output is correct |
57 |
Correct |
0 ms |
204 KB |
Output is correct |
58 |
Correct |
52 ms |
9772 KB |
Output is correct |
59 |
Correct |
53 ms |
9788 KB |
Output is correct |
60 |
Correct |
621 ms |
86160 KB |
Output is correct |
61 |
Correct |
54 ms |
9796 KB |
Output is correct |
62 |
Correct |
54 ms |
9792 KB |
Output is correct |
63 |
Correct |
54 ms |
9736 KB |
Output is correct |
64 |
Correct |
56 ms |
9736 KB |
Output is correct |
65 |
Correct |
64 ms |
9820 KB |
Output is correct |
66 |
Correct |
56 ms |
9760 KB |
Output is correct |
67 |
Correct |
52 ms |
9816 KB |
Output is correct |
68 |
Correct |
48 ms |
9728 KB |
Output is correct |
69 |
Correct |
56 ms |
9796 KB |
Output is correct |
70 |
Correct |
587 ms |
85900 KB |
Output is correct |
71 |
Correct |
56 ms |
9724 KB |
Output is correct |
72 |
Correct |
495 ms |
86224 KB |
Output is correct |
73 |
Correct |
510 ms |
86008 KB |
Output is correct |
74 |
Correct |
0 ms |
204 KB |
Output is correct |
75 |
Correct |
0 ms |
204 KB |
Output is correct |
76 |
Correct |
0 ms |
204 KB |
Output is correct |
77 |
Correct |
0 ms |
204 KB |
Output is correct |
78 |
Correct |
0 ms |
308 KB |
Output is correct |
79 |
Correct |
5 ms |
1476 KB |
Output is correct |
80 |
Correct |
643 ms |
86012 KB |
Output is correct |
81 |
Correct |
627 ms |
86132 KB |
Output is correct |
82 |
Correct |
586 ms |
86056 KB |
Output is correct |
83 |
Correct |
583 ms |
86060 KB |
Output is correct |
84 |
Correct |
592 ms |
85976 KB |
Output is correct |
85 |
Correct |
577 ms |
86016 KB |
Output is correct |
86 |
Correct |
142 ms |
34728 KB |
Output is correct |
87 |
Correct |
1 ms |
332 KB |
Output is correct |