#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;
ll m = a / __gcd (a, b + 1) * b;
// int tr = 0;
for (int i = 1; i <= n; ++i) {
ll l, r;
cin >> l >> r;
if (r - l + 1 >= m) {
v.pb ({0, m - 1});
// tr = 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});
}
}
// if (tr) {
// cout << m;
// return 0;
// }
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
3 ms |
1116 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
276 ms |
44956 KB |
Output is correct |
3 |
Incorrect |
285 ms |
44276 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
276 ms |
44956 KB |
Output is correct |
3 |
Incorrect |
285 ms |
44276 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
276 ms |
44956 KB |
Output is correct |
3 |
Incorrect |
285 ms |
44276 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
29 ms |
5284 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
3 ms |
1116 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |