#include <bits/stdc++.h>
#define int long long
using namespace std;
ostream& operator<<(ostream& out, __int128_t x){
string s; while(x) s.push_back(x % 10 + '0'), x /= 10;
reverse(s.begin(), s.end()); return out << s;
}
int32_t main(){
int n, a, b; cin >> n >> a >> b;
__int128_t c = (__int128_t) b * (a / __gcd(a, b + 1));
vector<pair<__int128_t, __int128_t>> d;
for(int i = 0; i < n; i++){
int l, r; cin >> l >> r;
if(r - l + 1 >= c){
cout << c << endl;
return 0;
}
if(l / c == r / c){
d.push_back({l % c, 1});
d.push_back({r % c + 1, -1});
}else{
d.push_back({l % c, 1});
d.push_back({0, 1});
d.push_back({r % c + 1, -1});
}
}
d.push_back({c, 0});
sort(d.begin(), d.end());
int cnt = 0, ans = 0;
for(int i = 0; i < d.size() - 1; i++){
cnt += d[i].second;
if(cnt > 0){
ans += d[i + 1].first - d[i].first;
}
}
cout << ans << endl;
}
Compilation message
strange_device.cpp: In function 'int32_t main()':
strange_device.cpp:32:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<__int128, __int128> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | for(int i = 0; i < d.size() - 1; i++){
| ~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
14 ms |
1836 KB |
Output is correct |
3 |
Correct |
17 ms |
1740 KB |
Output is correct |
4 |
Correct |
0 ms |
300 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
296 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 |
300 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
14 ms |
1988 KB |
Output is correct |
17 |
Correct |
150 ms |
11232 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
1016 ms |
88300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1447 ms |
100136 KB |
Output is correct |
3 |
Correct |
1481 ms |
100312 KB |
Output is correct |
4 |
Correct |
1408 ms |
100368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1447 ms |
100136 KB |
Output is correct |
3 |
Correct |
1481 ms |
100312 KB |
Output is correct |
4 |
Correct |
1408 ms |
100368 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1410 ms |
100376 KB |
Output is correct |
7 |
Correct |
1395 ms |
100240 KB |
Output is correct |
8 |
Correct |
1456 ms |
100260 KB |
Output is correct |
9 |
Correct |
1588 ms |
100132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1447 ms |
100136 KB |
Output is correct |
3 |
Correct |
1481 ms |
100312 KB |
Output is correct |
4 |
Correct |
1408 ms |
100368 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
143 ms |
11284 KB |
Output is correct |
7 |
Correct |
144 ms |
11240 KB |
Output is correct |
8 |
Correct |
145 ms |
11260 KB |
Output is correct |
9 |
Correct |
150 ms |
11312 KB |
Output is correct |
10 |
Correct |
138 ms |
11312 KB |
Output is correct |
11 |
Correct |
152 ms |
11212 KB |
Output is correct |
12 |
Correct |
140 ms |
11268 KB |
Output is correct |
13 |
Correct |
151 ms |
11184 KB |
Output is correct |
14 |
Correct |
143 ms |
11308 KB |
Output is correct |
15 |
Correct |
154 ms |
11276 KB |
Output is correct |
16 |
Correct |
148 ms |
11312 KB |
Output is correct |
17 |
Correct |
139 ms |
11196 KB |
Output is correct |
18 |
Correct |
1460 ms |
100200 KB |
Output is correct |
19 |
Correct |
1446 ms |
100164 KB |
Output is correct |
20 |
Correct |
1605 ms |
100120 KB |
Output is correct |
21 |
Correct |
172 ms |
11228 KB |
Output is correct |
22 |
Correct |
143 ms |
11184 KB |
Output is correct |
23 |
Correct |
459 ms |
42980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
428 KB |
Output is correct |
2 |
Correct |
153 ms |
11200 KB |
Output is correct |
3 |
Correct |
149 ms |
11252 KB |
Output is correct |
4 |
Correct |
1632 ms |
100028 KB |
Output is correct |
5 |
Correct |
152 ms |
11204 KB |
Output is correct |
6 |
Correct |
150 ms |
11264 KB |
Output is correct |
7 |
Correct |
147 ms |
11308 KB |
Output is correct |
8 |
Correct |
154 ms |
11184 KB |
Output is correct |
9 |
Correct |
151 ms |
11204 KB |
Output is correct |
10 |
Correct |
152 ms |
11180 KB |
Output is correct |
11 |
Correct |
146 ms |
11184 KB |
Output is correct |
12 |
Correct |
140 ms |
11352 KB |
Output is correct |
13 |
Correct |
156 ms |
11236 KB |
Output is correct |
14 |
Correct |
1593 ms |
100196 KB |
Output is correct |
15 |
Correct |
153 ms |
11184 KB |
Output is correct |
16 |
Correct |
1412 ms |
100248 KB |
Output is correct |
17 |
Correct |
1405 ms |
100168 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
14 ms |
1836 KB |
Output is correct |
3 |
Correct |
17 ms |
1740 KB |
Output is correct |
4 |
Correct |
0 ms |
300 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
296 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 |
300 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
14 ms |
1988 KB |
Output is correct |
17 |
Correct |
150 ms |
11232 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 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 |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
2 ms |
468 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
1016 ms |
88300 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
1447 ms |
100136 KB |
Output is correct |
31 |
Correct |
1481 ms |
100312 KB |
Output is correct |
32 |
Correct |
1408 ms |
100368 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
1410 ms |
100376 KB |
Output is correct |
35 |
Correct |
1395 ms |
100240 KB |
Output is correct |
36 |
Correct |
1456 ms |
100260 KB |
Output is correct |
37 |
Correct |
1588 ms |
100132 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
143 ms |
11284 KB |
Output is correct |
40 |
Correct |
144 ms |
11240 KB |
Output is correct |
41 |
Correct |
145 ms |
11260 KB |
Output is correct |
42 |
Correct |
150 ms |
11312 KB |
Output is correct |
43 |
Correct |
138 ms |
11312 KB |
Output is correct |
44 |
Correct |
152 ms |
11212 KB |
Output is correct |
45 |
Correct |
140 ms |
11268 KB |
Output is correct |
46 |
Correct |
151 ms |
11184 KB |
Output is correct |
47 |
Correct |
143 ms |
11308 KB |
Output is correct |
48 |
Correct |
154 ms |
11276 KB |
Output is correct |
49 |
Correct |
148 ms |
11312 KB |
Output is correct |
50 |
Correct |
139 ms |
11196 KB |
Output is correct |
51 |
Correct |
1460 ms |
100200 KB |
Output is correct |
52 |
Correct |
1446 ms |
100164 KB |
Output is correct |
53 |
Correct |
1605 ms |
100120 KB |
Output is correct |
54 |
Correct |
172 ms |
11228 KB |
Output is correct |
55 |
Correct |
143 ms |
11184 KB |
Output is correct |
56 |
Correct |
459 ms |
42980 KB |
Output is correct |
57 |
Correct |
1 ms |
428 KB |
Output is correct |
58 |
Correct |
153 ms |
11200 KB |
Output is correct |
59 |
Correct |
149 ms |
11252 KB |
Output is correct |
60 |
Correct |
1632 ms |
100028 KB |
Output is correct |
61 |
Correct |
152 ms |
11204 KB |
Output is correct |
62 |
Correct |
150 ms |
11264 KB |
Output is correct |
63 |
Correct |
147 ms |
11308 KB |
Output is correct |
64 |
Correct |
154 ms |
11184 KB |
Output is correct |
65 |
Correct |
151 ms |
11204 KB |
Output is correct |
66 |
Correct |
152 ms |
11180 KB |
Output is correct |
67 |
Correct |
146 ms |
11184 KB |
Output is correct |
68 |
Correct |
140 ms |
11352 KB |
Output is correct |
69 |
Correct |
156 ms |
11236 KB |
Output is correct |
70 |
Correct |
1593 ms |
100196 KB |
Output is correct |
71 |
Correct |
153 ms |
11184 KB |
Output is correct |
72 |
Correct |
1412 ms |
100248 KB |
Output is correct |
73 |
Correct |
1405 ms |
100168 KB |
Output is correct |
74 |
Correct |
1 ms |
212 KB |
Output is correct |
75 |
Correct |
0 ms |
300 KB |
Output is correct |
76 |
Correct |
0 ms |
300 KB |
Output is correct |
77 |
Correct |
0 ms |
212 KB |
Output is correct |
78 |
Correct |
1 ms |
212 KB |
Output is correct |
79 |
Correct |
14 ms |
1756 KB |
Output is correct |
80 |
Correct |
1611 ms |
100032 KB |
Output is correct |
81 |
Correct |
1652 ms |
99748 KB |
Output is correct |
82 |
Correct |
1671 ms |
99716 KB |
Output is correct |
83 |
Correct |
1598 ms |
99804 KB |
Output is correct |
84 |
Correct |
1585 ms |
99352 KB |
Output is correct |
85 |
Correct |
1621 ms |
99276 KB |
Output is correct |
86 |
Correct |
459 ms |
43104 KB |
Output is correct |
87 |
Correct |
0 ms |
212 KB |
Output is correct |