#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define sz size()
#define pii pair <ll, ll>
const int N = 1e6 + 5;
#define ll long long
#define pb push_back
vector <pii> v;
ll n, a, b;
int main () {
// freopen ("input.txt", "r", stdin);
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> a >> b;
__int128 m = a / __gcd (a, b + 1) * b;
for (int i = 1; i <= n; ++i) {
ll l, r;
cin >> l >> r;
if (r - l + 1 >= m) {
v.pb ({0, m - 1});
}
else if (l % m > r % m) {
v.pb ({l % m, m - 1});
v.pb ({0, r % m});
}
else {
v.pb ({l % m, r % m});
}
}
sort (v.begin(), v.end());
// for (auto i : v) {
// cout << i.ff << " " << i.ss << "\n";
// }
// return 0;
ll l = 0, r = 0, jogap = 0;
for (int i = 0; i < (int)v.sz; ++i) {
if (v[i].ff <= r) r = max (r, v[i].ff);
else {
jogap += r - l + 1;
l = v[i].ff;
r = v[i].ss;
}
}
jogap += r - l + 1;
cout << jogap;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Incorrect |
3 ms |
1116 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
285 ms |
53212 KB |
Output is correct |
3 |
Incorrect |
271 ms |
53136 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
285 ms |
53212 KB |
Output is correct |
3 |
Incorrect |
271 ms |
53136 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
285 ms |
53212 KB |
Output is correct |
3 |
Incorrect |
271 ms |
53136 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
29 ms |
5844 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Incorrect |
3 ms |
1116 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |