#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>> ranges;
for(int i = 0;i<N;++i){
int l,r; cin >> l >> r;
if(r-l+1 >= C){
cout << C << "\n";
return 0;
}
if(l/C == r/C){
ranges.push_back({l%C,1});
ranges.push_back({r%C + 1,-1});
}
else{
ranges.push_back({l%C,1});
ranges.push_back({0,1});
ranges.push_back({r%C+1,-1});
}
}
ranges.push_back({C, 0});
sort(ranges.begin(),ranges.end());
int cnt = 0, ans = 0;
for(int i = 0;i<ranges.size()-1;++i){
cnt += ranges[i].second;
if(cnt > 0){
ans += ranges[i+1].first-ranges[i].first;
}
}
cout << ans << "\n";
return 0;
}
Compilation message
strange_device.cpp: In function 'int32_t main()':
strange_device.cpp:33:17: 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]
33 | for(int i = 0;i<ranges.size()-1;++i){
| ~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
10 ms |
1512 KB |
Output is correct |
3 |
Correct |
10 ms |
1492 KB |
Output is correct |
4 |
Correct |
1 ms |
600 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
10 ms |
1492 KB |
Output is correct |
17 |
Correct |
111 ms |
9112 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
424 KB |
Output is correct |
5 |
Correct |
689 ms |
68032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
985 ms |
67740 KB |
Output is correct |
3 |
Correct |
1046 ms |
66552 KB |
Output is correct |
4 |
Correct |
938 ms |
66364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
985 ms |
67740 KB |
Output is correct |
3 |
Correct |
1046 ms |
66552 KB |
Output is correct |
4 |
Correct |
938 ms |
66364 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1020 ms |
66104 KB |
Output is correct |
7 |
Correct |
979 ms |
66976 KB |
Output is correct |
8 |
Correct |
1031 ms |
66768 KB |
Output is correct |
9 |
Correct |
1124 ms |
66488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
985 ms |
67740 KB |
Output is correct |
3 |
Correct |
1046 ms |
66552 KB |
Output is correct |
4 |
Correct |
938 ms |
66364 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
95 ms |
9360 KB |
Output is correct |
7 |
Correct |
100 ms |
9552 KB |
Output is correct |
8 |
Correct |
93 ms |
10680 KB |
Output is correct |
9 |
Correct |
111 ms |
9916 KB |
Output is correct |
10 |
Correct |
92 ms |
9656 KB |
Output is correct |
11 |
Correct |
101 ms |
8632 KB |
Output is correct |
12 |
Correct |
98 ms |
8760 KB |
Output is correct |
13 |
Correct |
103 ms |
10680 KB |
Output is correct |
14 |
Correct |
92 ms |
10684 KB |
Output is correct |
15 |
Correct |
102 ms |
10420 KB |
Output is correct |
16 |
Correct |
99 ms |
9144 KB |
Output is correct |
17 |
Correct |
97 ms |
9828 KB |
Output is correct |
18 |
Correct |
947 ms |
66972 KB |
Output is correct |
19 |
Correct |
958 ms |
66212 KB |
Output is correct |
20 |
Correct |
1096 ms |
66464 KB |
Output is correct |
21 |
Correct |
102 ms |
9396 KB |
Output is correct |
22 |
Correct |
99 ms |
10436 KB |
Output is correct |
23 |
Correct |
292 ms |
33544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
107 ms |
10668 KB |
Output is correct |
3 |
Correct |
108 ms |
9848 KB |
Output is correct |
4 |
Correct |
1109 ms |
66976 KB |
Output is correct |
5 |
Correct |
103 ms |
10688 KB |
Output is correct |
6 |
Correct |
101 ms |
9160 KB |
Output is correct |
7 |
Correct |
102 ms |
9140 KB |
Output is correct |
8 |
Correct |
102 ms |
8904 KB |
Output is correct |
9 |
Correct |
98 ms |
10428 KB |
Output is correct |
10 |
Correct |
105 ms |
10172 KB |
Output is correct |
11 |
Correct |
101 ms |
9996 KB |
Output is correct |
12 |
Correct |
101 ms |
9628 KB |
Output is correct |
13 |
Correct |
103 ms |
8904 KB |
Output is correct |
14 |
Correct |
1174 ms |
66416 KB |
Output is correct |
15 |
Correct |
104 ms |
10164 KB |
Output is correct |
16 |
Correct |
1000 ms |
67060 KB |
Output is correct |
17 |
Correct |
944 ms |
68000 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
10 ms |
1512 KB |
Output is correct |
3 |
Correct |
10 ms |
1492 KB |
Output is correct |
4 |
Correct |
1 ms |
600 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
10 ms |
1492 KB |
Output is correct |
17 |
Correct |
111 ms |
9112 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
2 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
424 KB |
Output is correct |
28 |
Correct |
689 ms |
68032 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
985 ms |
67740 KB |
Output is correct |
31 |
Correct |
1046 ms |
66552 KB |
Output is correct |
32 |
Correct |
938 ms |
66364 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |
34 |
Correct |
1020 ms |
66104 KB |
Output is correct |
35 |
Correct |
979 ms |
66976 KB |
Output is correct |
36 |
Correct |
1031 ms |
66768 KB |
Output is correct |
37 |
Correct |
1124 ms |
66488 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
95 ms |
9360 KB |
Output is correct |
40 |
Correct |
100 ms |
9552 KB |
Output is correct |
41 |
Correct |
93 ms |
10680 KB |
Output is correct |
42 |
Correct |
111 ms |
9916 KB |
Output is correct |
43 |
Correct |
92 ms |
9656 KB |
Output is correct |
44 |
Correct |
101 ms |
8632 KB |
Output is correct |
45 |
Correct |
98 ms |
8760 KB |
Output is correct |
46 |
Correct |
103 ms |
10680 KB |
Output is correct |
47 |
Correct |
92 ms |
10684 KB |
Output is correct |
48 |
Correct |
102 ms |
10420 KB |
Output is correct |
49 |
Correct |
99 ms |
9144 KB |
Output is correct |
50 |
Correct |
97 ms |
9828 KB |
Output is correct |
51 |
Correct |
947 ms |
66972 KB |
Output is correct |
52 |
Correct |
958 ms |
66212 KB |
Output is correct |
53 |
Correct |
1096 ms |
66464 KB |
Output is correct |
54 |
Correct |
102 ms |
9396 KB |
Output is correct |
55 |
Correct |
99 ms |
10436 KB |
Output is correct |
56 |
Correct |
292 ms |
33544 KB |
Output is correct |
57 |
Correct |
0 ms |
348 KB |
Output is correct |
58 |
Correct |
107 ms |
10668 KB |
Output is correct |
59 |
Correct |
108 ms |
9848 KB |
Output is correct |
60 |
Correct |
1109 ms |
66976 KB |
Output is correct |
61 |
Correct |
103 ms |
10688 KB |
Output is correct |
62 |
Correct |
101 ms |
9160 KB |
Output is correct |
63 |
Correct |
102 ms |
9140 KB |
Output is correct |
64 |
Correct |
102 ms |
8904 KB |
Output is correct |
65 |
Correct |
98 ms |
10428 KB |
Output is correct |
66 |
Correct |
105 ms |
10172 KB |
Output is correct |
67 |
Correct |
101 ms |
9996 KB |
Output is correct |
68 |
Correct |
101 ms |
9628 KB |
Output is correct |
69 |
Correct |
103 ms |
8904 KB |
Output is correct |
70 |
Correct |
1174 ms |
66416 KB |
Output is correct |
71 |
Correct |
104 ms |
10164 KB |
Output is correct |
72 |
Correct |
1000 ms |
67060 KB |
Output is correct |
73 |
Correct |
944 ms |
68000 KB |
Output is correct |
74 |
Correct |
0 ms |
348 KB |
Output is correct |
75 |
Correct |
0 ms |
344 KB |
Output is correct |
76 |
Correct |
0 ms |
348 KB |
Output is correct |
77 |
Correct |
0 ms |
348 KB |
Output is correct |
78 |
Correct |
0 ms |
344 KB |
Output is correct |
79 |
Correct |
10 ms |
1748 KB |
Output is correct |
80 |
Correct |
1136 ms |
101520 KB |
Output is correct |
81 |
Correct |
1109 ms |
101956 KB |
Output is correct |
82 |
Correct |
1024 ms |
101184 KB |
Output is correct |
83 |
Correct |
1030 ms |
101272 KB |
Output is correct |
84 |
Correct |
1029 ms |
101312 KB |
Output is correct |
85 |
Correct |
1045 ms |
100448 KB |
Output is correct |
86 |
Correct |
303 ms |
43432 KB |
Output is correct |
87 |
Correct |
0 ms |
348 KB |
Output is correct |