#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
typedef pair<int64, int64> ii;
int N;
int64 A, B, per, ans;
vector<ii> ar;
int main(){
ios::sync_with_stdio(0), cin.tie(0);
cin >> N >> A >> B;
if(A / __gcd(A, B + 1) >= LLONG_MAX / B) per = LLONG_MAX;
else per = A / __gcd(A, B + 1) * B;
for(int64 i = 0, u, v; i < N; ++i){
cin >> u >> v;
if(v - u + 1 >= per) {cout << per; return 0;}
u %= per, v %= per;
if(u <= v) ar.emplace_back(u, v);
else ar.emplace_back(u, per - 1), ar.emplace_back(0, v);
}
sort(ar.begin(), ar.end());
for(int64 i = 0, l = 0, r = -1;; ++i){
if(i == ar.size()) {ans += r - l + 1; break;}
if(ar[i].first <= r) r = max(r, ar[i].second);
else ans += r - l + 1, l = ar[i].first, r = ar[i].second;
}
cout << ans;
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:22:14: warning: comparison of integer expressions of different signedness: 'int64' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | if(i == ar.size()) {ans += r - l + 1; break;}
| ~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
5 ms |
976 KB |
Output is correct |
3 |
Correct |
7 ms |
976 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
320 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
208 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
316 KB |
Output is correct |
16 |
Correct |
5 ms |
976 KB |
Output is correct |
17 |
Correct |
50 ms |
2904 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
2 ms |
332 KB |
Output is correct |
5 |
Correct |
329 ms |
16852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
461 ms |
17344 KB |
Output is correct |
3 |
Correct |
452 ms |
17344 KB |
Output is correct |
4 |
Correct |
439 ms |
17316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
461 ms |
17344 KB |
Output is correct |
3 |
Correct |
452 ms |
17344 KB |
Output is correct |
4 |
Correct |
439 ms |
17316 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
481 ms |
17368 KB |
Output is correct |
7 |
Correct |
464 ms |
17316 KB |
Output is correct |
8 |
Correct |
486 ms |
17340 KB |
Output is correct |
9 |
Correct |
505 ms |
17312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
461 ms |
17344 KB |
Output is correct |
3 |
Correct |
452 ms |
17344 KB |
Output is correct |
4 |
Correct |
439 ms |
17316 KB |
Output is correct |
5 |
Correct |
1 ms |
316 KB |
Output is correct |
6 |
Correct |
45 ms |
2844 KB |
Output is correct |
7 |
Correct |
48 ms |
2880 KB |
Output is correct |
8 |
Correct |
44 ms |
2864 KB |
Output is correct |
9 |
Correct |
46 ms |
3008 KB |
Output is correct |
10 |
Correct |
44 ms |
2908 KB |
Output is correct |
11 |
Correct |
47 ms |
2952 KB |
Output is correct |
12 |
Correct |
44 ms |
2868 KB |
Output is correct |
13 |
Correct |
48 ms |
2880 KB |
Output is correct |
14 |
Correct |
44 ms |
2852 KB |
Output is correct |
15 |
Correct |
51 ms |
2964 KB |
Output is correct |
16 |
Correct |
51 ms |
2880 KB |
Output is correct |
17 |
Correct |
45 ms |
2924 KB |
Output is correct |
18 |
Correct |
453 ms |
17224 KB |
Output is correct |
19 |
Correct |
454 ms |
17536 KB |
Output is correct |
20 |
Correct |
506 ms |
17268 KB |
Output is correct |
21 |
Correct |
48 ms |
2888 KB |
Output is correct |
22 |
Correct |
42 ms |
2888 KB |
Output is correct |
23 |
Correct |
140 ms |
9104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
49 ms |
2960 KB |
Output is correct |
3 |
Correct |
52 ms |
2880 KB |
Output is correct |
4 |
Correct |
520 ms |
17172 KB |
Output is correct |
5 |
Correct |
47 ms |
2888 KB |
Output is correct |
6 |
Correct |
48 ms |
2880 KB |
Output is correct |
7 |
Correct |
48 ms |
2888 KB |
Output is correct |
8 |
Correct |
49 ms |
2860 KB |
Output is correct |
9 |
Correct |
58 ms |
2884 KB |
Output is correct |
10 |
Correct |
48 ms |
2828 KB |
Output is correct |
11 |
Correct |
49 ms |
2684 KB |
Output is correct |
12 |
Correct |
44 ms |
2752 KB |
Output is correct |
13 |
Correct |
48 ms |
2752 KB |
Output is correct |
14 |
Correct |
493 ms |
17104 KB |
Output is correct |
15 |
Correct |
48 ms |
2760 KB |
Output is correct |
16 |
Correct |
448 ms |
17116 KB |
Output is correct |
17 |
Correct |
449 ms |
17060 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
5 ms |
976 KB |
Output is correct |
3 |
Correct |
7 ms |
976 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
320 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
208 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
316 KB |
Output is correct |
16 |
Correct |
5 ms |
976 KB |
Output is correct |
17 |
Correct |
50 ms |
2904 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
1 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 |
2 ms |
332 KB |
Output is correct |
28 |
Correct |
329 ms |
16852 KB |
Output is correct |
29 |
Correct |
1 ms |
256 KB |
Output is correct |
30 |
Correct |
461 ms |
17344 KB |
Output is correct |
31 |
Correct |
452 ms |
17344 KB |
Output is correct |
32 |
Correct |
439 ms |
17316 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
481 ms |
17368 KB |
Output is correct |
35 |
Correct |
464 ms |
17316 KB |
Output is correct |
36 |
Correct |
486 ms |
17340 KB |
Output is correct |
37 |
Correct |
505 ms |
17312 KB |
Output is correct |
38 |
Correct |
1 ms |
316 KB |
Output is correct |
39 |
Correct |
45 ms |
2844 KB |
Output is correct |
40 |
Correct |
48 ms |
2880 KB |
Output is correct |
41 |
Correct |
44 ms |
2864 KB |
Output is correct |
42 |
Correct |
46 ms |
3008 KB |
Output is correct |
43 |
Correct |
44 ms |
2908 KB |
Output is correct |
44 |
Correct |
47 ms |
2952 KB |
Output is correct |
45 |
Correct |
44 ms |
2868 KB |
Output is correct |
46 |
Correct |
48 ms |
2880 KB |
Output is correct |
47 |
Correct |
44 ms |
2852 KB |
Output is correct |
48 |
Correct |
51 ms |
2964 KB |
Output is correct |
49 |
Correct |
51 ms |
2880 KB |
Output is correct |
50 |
Correct |
45 ms |
2924 KB |
Output is correct |
51 |
Correct |
453 ms |
17224 KB |
Output is correct |
52 |
Correct |
454 ms |
17536 KB |
Output is correct |
53 |
Correct |
506 ms |
17268 KB |
Output is correct |
54 |
Correct |
48 ms |
2888 KB |
Output is correct |
55 |
Correct |
42 ms |
2888 KB |
Output is correct |
56 |
Correct |
140 ms |
9104 KB |
Output is correct |
57 |
Correct |
1 ms |
204 KB |
Output is correct |
58 |
Correct |
49 ms |
2960 KB |
Output is correct |
59 |
Correct |
52 ms |
2880 KB |
Output is correct |
60 |
Correct |
520 ms |
17172 KB |
Output is correct |
61 |
Correct |
47 ms |
2888 KB |
Output is correct |
62 |
Correct |
48 ms |
2880 KB |
Output is correct |
63 |
Correct |
48 ms |
2888 KB |
Output is correct |
64 |
Correct |
49 ms |
2860 KB |
Output is correct |
65 |
Correct |
58 ms |
2884 KB |
Output is correct |
66 |
Correct |
48 ms |
2828 KB |
Output is correct |
67 |
Correct |
49 ms |
2684 KB |
Output is correct |
68 |
Correct |
44 ms |
2752 KB |
Output is correct |
69 |
Correct |
48 ms |
2752 KB |
Output is correct |
70 |
Correct |
493 ms |
17104 KB |
Output is correct |
71 |
Correct |
48 ms |
2760 KB |
Output is correct |
72 |
Correct |
448 ms |
17116 KB |
Output is correct |
73 |
Correct |
449 ms |
17060 KB |
Output is correct |
74 |
Correct |
1 ms |
204 KB |
Output is correct |
75 |
Correct |
1 ms |
204 KB |
Output is correct |
76 |
Correct |
1 ms |
204 KB |
Output is correct |
77 |
Correct |
1 ms |
204 KB |
Output is correct |
78 |
Correct |
1 ms |
204 KB |
Output is correct |
79 |
Correct |
5 ms |
976 KB |
Output is correct |
80 |
Correct |
533 ms |
31940 KB |
Output is correct |
81 |
Correct |
533 ms |
32040 KB |
Output is correct |
82 |
Correct |
500 ms |
32036 KB |
Output is correct |
83 |
Correct |
502 ms |
32036 KB |
Output is correct |
84 |
Correct |
502 ms |
32036 KB |
Output is correct |
85 |
Correct |
495 ms |
32112 KB |
Output is correct |
86 |
Correct |
142 ms |
18480 KB |
Output is correct |
87 |
Correct |
1 ms |
204 KB |
Output is correct |