#include<bits/stdc++.h>
#define maxn 1000005
using namespace std;
typedef long long ll;
ll n, A, B;
ll l[maxn], r[maxn];
ll ret = 0;
int main(){
// BASIC BASE
cin >> n >> A >> B;
for (ll i = 0; i < n; ++i)
cin >> l[i] >> r[i];
ll ret = A / __gcd(A, B + 1);
if (sqrt(ret) * sqrt(B) > 1e9){
ll ans = 0;
for (ll i = 0; i < n; ++i)
ans += r[i] - l[i];
cout << ans;
return 0;
}
ret *= B;
ll ans = 0;
for (ll i = 0; i < n; ++i)
if (l[i] + ret <= r[i]) return cout << ret, 0;
else l[i] %= ret, r[i] %= ret;
vector < pair <ll, ll> > a;
ll L = 0, R = ret;
for (ll i = 0; i < n; ++i)
if (l[i] > r[i]) L = max(L, r[i] + 1), R = min(R, l[i]);
else a.push_back({l[i], r[i]});
if (L > R) return cout << ret, 0;
sort(a.begin(), a.end());
ans = ret;
for (auto i : a){
if (i.first >= L) ans -= min(R, i.first) - L;
L = max(L, min(R, i.second + 1));
}
ans -= R - L;
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
26 ms |
1272 KB |
Output is correct |
3 |
Correct |
28 ms |
1272 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
256 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
26 ms |
1324 KB |
Output is correct |
17 |
Correct |
227 ms |
7828 KB |
Output is correct |
18 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
7 ms |
384 KB |
Output is correct |
3 |
Correct |
7 ms |
384 KB |
Output is correct |
4 |
Correct |
7 ms |
384 KB |
Output is correct |
5 |
Correct |
1548 ms |
51092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
2154 ms |
38760 KB |
Output is correct |
3 |
Correct |
2143 ms |
38748 KB |
Output is correct |
4 |
Correct |
2164 ms |
38936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
2154 ms |
38760 KB |
Output is correct |
3 |
Correct |
2143 ms |
38748 KB |
Output is correct |
4 |
Correct |
2164 ms |
38936 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
2153 ms |
39036 KB |
Output is correct |
7 |
Correct |
2151 ms |
38972 KB |
Output is correct |
8 |
Correct |
2130 ms |
38836 KB |
Output is correct |
9 |
Correct |
2197 ms |
39228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
2154 ms |
38760 KB |
Output is correct |
3 |
Correct |
2143 ms |
38748 KB |
Output is correct |
4 |
Correct |
2164 ms |
38936 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
223 ms |
7792 KB |
Output is correct |
7 |
Correct |
223 ms |
7916 KB |
Output is correct |
8 |
Correct |
221 ms |
7916 KB |
Output is correct |
9 |
Correct |
219 ms |
7788 KB |
Output is correct |
10 |
Correct |
220 ms |
7660 KB |
Output is correct |
11 |
Correct |
219 ms |
7788 KB |
Output is correct |
12 |
Correct |
216 ms |
7788 KB |
Output is correct |
13 |
Correct |
222 ms |
7792 KB |
Output is correct |
14 |
Correct |
218 ms |
7788 KB |
Output is correct |
15 |
Correct |
222 ms |
7788 KB |
Output is correct |
16 |
Correct |
227 ms |
7788 KB |
Output is correct |
17 |
Correct |
218 ms |
7792 KB |
Output is correct |
18 |
Correct |
2161 ms |
39004 KB |
Output is correct |
19 |
Correct |
2356 ms |
39012 KB |
Output is correct |
20 |
Correct |
2200 ms |
38968 KB |
Output is correct |
21 |
Correct |
224 ms |
7788 KB |
Output is correct |
22 |
Correct |
218 ms |
7960 KB |
Output is correct |
23 |
Correct |
726 ms |
26636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
226 ms |
7912 KB |
Output is correct |
3 |
Correct |
224 ms |
7788 KB |
Output is correct |
4 |
Correct |
2222 ms |
53400 KB |
Output is correct |
5 |
Correct |
226 ms |
7788 KB |
Output is correct |
6 |
Correct |
225 ms |
7788 KB |
Output is correct |
7 |
Correct |
222 ms |
7916 KB |
Output is correct |
8 |
Correct |
226 ms |
7792 KB |
Output is correct |
9 |
Correct |
223 ms |
7788 KB |
Output is correct |
10 |
Correct |
228 ms |
7792 KB |
Output is correct |
11 |
Correct |
224 ms |
7788 KB |
Output is correct |
12 |
Correct |
218 ms |
7788 KB |
Output is correct |
13 |
Correct |
223 ms |
8032 KB |
Output is correct |
14 |
Correct |
2202 ms |
53248 KB |
Output is correct |
15 |
Correct |
223 ms |
7788 KB |
Output is correct |
16 |
Correct |
2146 ms |
39056 KB |
Output is correct |
17 |
Correct |
2136 ms |
39136 KB |
Output is correct |
18 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
26 ms |
1272 KB |
Output is correct |
3 |
Correct |
28 ms |
1272 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
256 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
26 ms |
1324 KB |
Output is correct |
17 |
Correct |
227 ms |
7828 KB |
Output is correct |
18 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |