#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;
per = A / __gcd(A, B + 1) * B;
cout << per << '\n';
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(auto [u, v]: ar) cout << u << ' ' << v << '\n';
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:24: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]
24 | if(i == ar.size()) {ans += r - l + 1; break;}
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |