#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
int main() {
ios :: sync_with_stdio(0); cin.tie(0);
int n;
long long A, B;
vector <pair <long long, int> > events;
cin >> n >> A >> B;
long long T;
if (1.0L * A / __gcd(A, B + 1) * B > 2e18) T = 2e18;
else T = A / __gcd(A, B + 1) * B;
for (int i = 0; i < n; ++i) {
long long L, R;
cin >> L >> R;
if (R - L + 1 >= T) {
cout << T << '\n';
exit(0);
}
L %= T, R %= T;
if (L <= R) {
events.push_back({L, 1});
events.push_back({R + 1, -1});
} else {
events.push_back({L, 1});
events.push_back({T, -1});
events.push_back({0, 1});
events.push_back({R + 1, -1});
}
}
sort(events.begin(), events.end());
int cur = 0;
long long ans = 0;
for (int i = 0; i + 1 < events.size(); ++i) {
cur += events[i].second;
if (cur != 0) ans += events[i + 1].first - events[i].first;
}
cout << ans;
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:45:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for (int i = 0; i + 1 < events.size(); ++i) {
| ~~~~~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
940 KB |
Output is correct |
3 |
Correct |
5 ms |
984 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
856 KB |
Output is correct |
17 |
Correct |
59 ms |
4580 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
323 ms |
33240 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
481 ms |
33180 KB |
Output is correct |
3 |
Correct |
495 ms |
33288 KB |
Output is correct |
4 |
Correct |
461 ms |
33172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
481 ms |
33180 KB |
Output is correct |
3 |
Correct |
495 ms |
33288 KB |
Output is correct |
4 |
Correct |
461 ms |
33172 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
487 ms |
33192 KB |
Output is correct |
7 |
Correct |
483 ms |
33292 KB |
Output is correct |
8 |
Correct |
470 ms |
33200 KB |
Output is correct |
9 |
Correct |
561 ms |
33252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
481 ms |
33180 KB |
Output is correct |
3 |
Correct |
495 ms |
33288 KB |
Output is correct |
4 |
Correct |
461 ms |
33172 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
49 ms |
4540 KB |
Output is correct |
7 |
Correct |
51 ms |
4556 KB |
Output is correct |
8 |
Correct |
46 ms |
4544 KB |
Output is correct |
9 |
Correct |
46 ms |
4556 KB |
Output is correct |
10 |
Correct |
44 ms |
4704 KB |
Output is correct |
11 |
Correct |
48 ms |
4484 KB |
Output is correct |
12 |
Correct |
45 ms |
4520 KB |
Output is correct |
13 |
Correct |
48 ms |
4516 KB |
Output is correct |
14 |
Correct |
46 ms |
4556 KB |
Output is correct |
15 |
Correct |
53 ms |
4512 KB |
Output is correct |
16 |
Correct |
57 ms |
4484 KB |
Output is correct |
17 |
Correct |
48 ms |
4472 KB |
Output is correct |
18 |
Correct |
487 ms |
33284 KB |
Output is correct |
19 |
Correct |
467 ms |
33172 KB |
Output is correct |
20 |
Correct |
587 ms |
33216 KB |
Output is correct |
21 |
Correct |
53 ms |
4436 KB |
Output is correct |
22 |
Correct |
41 ms |
4576 KB |
Output is correct |
23 |
Correct |
132 ms |
16836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
50 ms |
4532 KB |
Output is correct |
3 |
Correct |
56 ms |
4556 KB |
Output is correct |
4 |
Correct |
608 ms |
33212 KB |
Output is correct |
5 |
Correct |
49 ms |
4556 KB |
Output is correct |
6 |
Correct |
50 ms |
4496 KB |
Output is correct |
7 |
Correct |
55 ms |
4484 KB |
Output is correct |
8 |
Correct |
57 ms |
4536 KB |
Output is correct |
9 |
Correct |
49 ms |
4556 KB |
Output is correct |
10 |
Correct |
53 ms |
4532 KB |
Output is correct |
11 |
Correct |
61 ms |
4444 KB |
Output is correct |
12 |
Correct |
46 ms |
4556 KB |
Output is correct |
13 |
Correct |
57 ms |
4548 KB |
Output is correct |
14 |
Correct |
566 ms |
33276 KB |
Output is correct |
15 |
Correct |
52 ms |
4548 KB |
Output is correct |
16 |
Correct |
452 ms |
33180 KB |
Output is correct |
17 |
Correct |
476 ms |
33212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
940 KB |
Output is correct |
3 |
Correct |
5 ms |
984 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
856 KB |
Output is correct |
17 |
Correct |
59 ms |
4580 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
323 ms |
33240 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
481 ms |
33180 KB |
Output is correct |
31 |
Correct |
495 ms |
33288 KB |
Output is correct |
32 |
Correct |
461 ms |
33172 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
487 ms |
33192 KB |
Output is correct |
35 |
Correct |
483 ms |
33292 KB |
Output is correct |
36 |
Correct |
470 ms |
33200 KB |
Output is correct |
37 |
Correct |
561 ms |
33252 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
49 ms |
4540 KB |
Output is correct |
40 |
Correct |
51 ms |
4556 KB |
Output is correct |
41 |
Correct |
46 ms |
4544 KB |
Output is correct |
42 |
Correct |
46 ms |
4556 KB |
Output is correct |
43 |
Correct |
44 ms |
4704 KB |
Output is correct |
44 |
Correct |
48 ms |
4484 KB |
Output is correct |
45 |
Correct |
45 ms |
4520 KB |
Output is correct |
46 |
Correct |
48 ms |
4516 KB |
Output is correct |
47 |
Correct |
46 ms |
4556 KB |
Output is correct |
48 |
Correct |
53 ms |
4512 KB |
Output is correct |
49 |
Correct |
57 ms |
4484 KB |
Output is correct |
50 |
Correct |
48 ms |
4472 KB |
Output is correct |
51 |
Correct |
487 ms |
33284 KB |
Output is correct |
52 |
Correct |
467 ms |
33172 KB |
Output is correct |
53 |
Correct |
587 ms |
33216 KB |
Output is correct |
54 |
Correct |
53 ms |
4436 KB |
Output is correct |
55 |
Correct |
41 ms |
4576 KB |
Output is correct |
56 |
Correct |
132 ms |
16836 KB |
Output is correct |
57 |
Correct |
0 ms |
212 KB |
Output is correct |
58 |
Correct |
50 ms |
4532 KB |
Output is correct |
59 |
Correct |
56 ms |
4556 KB |
Output is correct |
60 |
Correct |
608 ms |
33212 KB |
Output is correct |
61 |
Correct |
49 ms |
4556 KB |
Output is correct |
62 |
Correct |
50 ms |
4496 KB |
Output is correct |
63 |
Correct |
55 ms |
4484 KB |
Output is correct |
64 |
Correct |
57 ms |
4536 KB |
Output is correct |
65 |
Correct |
49 ms |
4556 KB |
Output is correct |
66 |
Correct |
53 ms |
4532 KB |
Output is correct |
67 |
Correct |
61 ms |
4444 KB |
Output is correct |
68 |
Correct |
46 ms |
4556 KB |
Output is correct |
69 |
Correct |
57 ms |
4548 KB |
Output is correct |
70 |
Correct |
566 ms |
33276 KB |
Output is correct |
71 |
Correct |
52 ms |
4548 KB |
Output is correct |
72 |
Correct |
452 ms |
33180 KB |
Output is correct |
73 |
Correct |
476 ms |
33212 KB |
Output is correct |
74 |
Correct |
0 ms |
212 KB |
Output is correct |
75 |
Correct |
1 ms |
212 KB |
Output is correct |
76 |
Correct |
1 ms |
320 KB |
Output is correct |
77 |
Correct |
1 ms |
212 KB |
Output is correct |
78 |
Correct |
1 ms |
212 KB |
Output is correct |
79 |
Correct |
5 ms |
1232 KB |
Output is correct |
80 |
Correct |
605 ms |
33932 KB |
Output is correct |
81 |
Correct |
624 ms |
33944 KB |
Output is correct |
82 |
Correct |
573 ms |
33928 KB |
Output is correct |
83 |
Correct |
562 ms |
33940 KB |
Output is correct |
84 |
Correct |
559 ms |
33920 KB |
Output is correct |
85 |
Correct |
558 ms |
34172 KB |
Output is correct |
86 |
Correct |
144 ms |
20644 KB |
Output is correct |
87 |
Correct |
1 ms |
316 KB |
Output is correct |