#include <bits/stdc++.h>
using namespace std;
#define int long long
// #define i128 long long
#define i128 __int128_t
int n, a, b;
vector<pair<int, int>> sg;
const int maks = 1e18;
// i128 gcd(i128 a, i128 b) {
// if (b == 0) return a;
// return gcd(b, a%b);
// }
bool comp(pair<int, int> a, pair<int, int> b) {
return (a.first < b.first or (a.first == b.first and a.second < b.second));
}
signed main() {
i128 temp;
// int temp;
i128 size;
cin >> n >> a >> b;
// temp = a*b;
// temp = ((i128)a/__gcd(a,b+1))*(i128)b;
if ((b+1 % a) == 0) size = b;
if (temp > maks) size = maks;
else size = temp;
// size = temp;
int l, r;
for (int i = 0; i < n; i++) {
cin >> l >> r;
// cout << l << " " << r << endl;
if (r - l + 1 >= size) {
cout << (int)size << endl;
return 0;
} else if (l%size > r%size) {
sg.push_back({l%size, 1});
sg.push_back({size-1, 2});
sg.push_back({0, 1});
sg.push_back({r%size, 2});
} else {
sg.push_back({l%size, 1});
sg.push_back({r%size, 2});
}
}
sort(sg.begin(), sg.end(), comp);
int cnt = 0, l2;
vector<pair<int, int>> ans;
for (int i = 0; i < sg.size(); i++) {
// cout << sg[i].first << " " << sg[i].second << endl;
if (sg[i].second == 1) {
if (cnt == 0) l2 = sg[i].first;
cnt++;
} else cnt--;
if (cnt == 0) {
ans.push_back({l2, sg[i].first});
// ans += sg[i].first-l2+1.;
}
}
// cout << ans << endl;
int res = 0;
for (auto i: ans) {
// cout << i.first << " " << i.second << endl;
res += (i.second - i.first + 1);
}
cout << res << endl;
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:54:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | for (int i = 0; i < sg.size(); i++) {
| ~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
13 ms |
1228 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1357 ms |
64112 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1357 ms |
64112 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1357 ms |
64112 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
300 KB |
Output is correct |
2 |
Incorrect |
130 ms |
7688 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
13 ms |
1228 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |