#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].ss);
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 |
348 KB |
Output is correct |
2 |
Incorrect |
3 ms |
732 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 |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
1 ms |
504 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
187 ms |
41328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
258 ms |
16988 KB |
Output is correct |
3 |
Correct |
302 ms |
16820 KB |
Output is correct |
4 |
Correct |
268 ms |
53244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
258 ms |
16988 KB |
Output is correct |
3 |
Correct |
302 ms |
16820 KB |
Output is correct |
4 |
Correct |
268 ms |
53244 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
272 ms |
53156 KB |
Output is correct |
7 |
Correct |
261 ms |
53148 KB |
Output is correct |
8 |
Correct |
267 ms |
53260 KB |
Output is correct |
9 |
Incorrect |
291 ms |
53128 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
258 ms |
16988 KB |
Output is correct |
3 |
Correct |
302 ms |
16820 KB |
Output is correct |
4 |
Correct |
268 ms |
53244 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
29 ms |
5820 KB |
Output is correct |
7 |
Correct |
28 ms |
5832 KB |
Output is correct |
8 |
Correct |
26 ms |
5844 KB |
Output is correct |
9 |
Correct |
27 ms |
5832 KB |
Output is correct |
10 |
Correct |
26 ms |
5832 KB |
Output is correct |
11 |
Correct |
27 ms |
5832 KB |
Output is correct |
12 |
Correct |
25 ms |
5740 KB |
Output is correct |
13 |
Incorrect |
28 ms |
5832 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
27 ms |
2520 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 |
Incorrect |
3 ms |
732 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |