#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
const ll N = 1000005;
const ll lim = 1e18;
pair <ll, ll> arr[N];
int main() {
ll n, a, b, t, m, i, sz, l, r, ans;
cin >> n >> a >> b;
t = a / (__gcd(a, b + 1));
m = ((t > lim / b) ? (lim + 1) : (t * b));
sz = 0;
while(n--) {
cin >> l >> r;
if(r - l + 1 >= m) {
cout << m << "\n";
return 0;
}
l %= m;
r %= m;
if(l <= r) {
arr[++sz].F = l;
arr[sz].S = r;
}
else {
arr[++sz].F = l;
arr[sz].S = m - 1;
arr[++sz].F = 0;
arr[sz].S = r;
}
}
sort(arr + 1, arr + sz + 1);
ans = 0; r = -1;
for(i = 1; i <= sz; i++) {
r = max(r, arr[i].F - 1);
ans += max(0ll, arr[i].S - r);
r = max(r, arr[i].S);
}
cout << ans << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
22 ms |
512 KB |
Output is correct |
3 |
Correct |
22 ms |
512 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
0 ms |
256 KB |
Output is correct |
10 |
Correct |
0 ms |
256 KB |
Output is correct |
11 |
Correct |
0 ms |
256 KB |
Output is correct |
12 |
Correct |
1 ms |
256 KB |
Output is correct |
13 |
Correct |
1 ms |
256 KB |
Output is correct |
14 |
Correct |
0 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
22 ms |
512 KB |
Output is correct |
17 |
Correct |
224 ms |
1832 KB |
Output is correct |
18 |
Correct |
0 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
1488 ms |
16108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
2089 ms |
16092 KB |
Output is correct |
3 |
Correct |
2096 ms |
16024 KB |
Output is correct |
4 |
Correct |
2106 ms |
16036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
2089 ms |
16092 KB |
Output is correct |
3 |
Correct |
2096 ms |
16024 KB |
Output is correct |
4 |
Correct |
2106 ms |
16036 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
2117 ms |
16016 KB |
Output is correct |
7 |
Correct |
2133 ms |
15988 KB |
Output is correct |
8 |
Correct |
2133 ms |
16024 KB |
Output is correct |
9 |
Correct |
2178 ms |
16060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
2089 ms |
16092 KB |
Output is correct |
3 |
Correct |
2096 ms |
16024 KB |
Output is correct |
4 |
Correct |
2106 ms |
16036 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
210 ms |
1912 KB |
Output is correct |
7 |
Correct |
210 ms |
1912 KB |
Output is correct |
8 |
Correct |
210 ms |
1912 KB |
Output is correct |
9 |
Correct |
210 ms |
1912 KB |
Output is correct |
10 |
Correct |
209 ms |
1912 KB |
Output is correct |
11 |
Correct |
212 ms |
1912 KB |
Output is correct |
12 |
Correct |
207 ms |
1912 KB |
Output is correct |
13 |
Correct |
211 ms |
1916 KB |
Output is correct |
14 |
Correct |
211 ms |
1916 KB |
Output is correct |
15 |
Correct |
214 ms |
1912 KB |
Output is correct |
16 |
Correct |
213 ms |
1916 KB |
Output is correct |
17 |
Correct |
214 ms |
1912 KB |
Output is correct |
18 |
Correct |
2095 ms |
16044 KB |
Output is correct |
19 |
Correct |
2074 ms |
16120 KB |
Output is correct |
20 |
Correct |
2146 ms |
15944 KB |
Output is correct |
21 |
Correct |
215 ms |
1912 KB |
Output is correct |
22 |
Correct |
209 ms |
1912 KB |
Output is correct |
23 |
Correct |
704 ms |
5752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
209 ms |
2040 KB |
Output is correct |
3 |
Correct |
233 ms |
1912 KB |
Output is correct |
4 |
Correct |
2305 ms |
15992 KB |
Output is correct |
5 |
Correct |
222 ms |
2040 KB |
Output is correct |
6 |
Correct |
215 ms |
2040 KB |
Output is correct |
7 |
Correct |
208 ms |
1912 KB |
Output is correct |
8 |
Correct |
214 ms |
1884 KB |
Output is correct |
9 |
Correct |
221 ms |
1928 KB |
Output is correct |
10 |
Correct |
210 ms |
1912 KB |
Output is correct |
11 |
Correct |
213 ms |
1912 KB |
Output is correct |
12 |
Correct |
207 ms |
1912 KB |
Output is correct |
13 |
Correct |
213 ms |
1912 KB |
Output is correct |
14 |
Correct |
2139 ms |
15944 KB |
Output is correct |
15 |
Correct |
215 ms |
1912 KB |
Output is correct |
16 |
Correct |
2101 ms |
16120 KB |
Output is correct |
17 |
Correct |
2074 ms |
16032 KB |
Output is correct |
18 |
Correct |
0 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
22 ms |
512 KB |
Output is correct |
3 |
Correct |
22 ms |
512 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
0 ms |
256 KB |
Output is correct |
10 |
Correct |
0 ms |
256 KB |
Output is correct |
11 |
Correct |
0 ms |
256 KB |
Output is correct |
12 |
Correct |
1 ms |
256 KB |
Output is correct |
13 |
Correct |
1 ms |
256 KB |
Output is correct |
14 |
Correct |
0 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
22 ms |
512 KB |
Output is correct |
17 |
Correct |
224 ms |
1832 KB |
Output is correct |
18 |
Correct |
0 ms |
256 KB |
Output is correct |
19 |
Correct |
0 ms |
256 KB |
Output is correct |
20 |
Correct |
0 ms |
256 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
256 KB |
Output is correct |
23 |
Correct |
0 ms |
256 KB |
Output is correct |
24 |
Correct |
1 ms |
256 KB |
Output is correct |
25 |
Correct |
2 ms |
384 KB |
Output is correct |
26 |
Correct |
3 ms |
384 KB |
Output is correct |
27 |
Correct |
3 ms |
384 KB |
Output is correct |
28 |
Correct |
1488 ms |
16108 KB |
Output is correct |
29 |
Correct |
0 ms |
256 KB |
Output is correct |
30 |
Correct |
2089 ms |
16092 KB |
Output is correct |
31 |
Correct |
2096 ms |
16024 KB |
Output is correct |
32 |
Correct |
2106 ms |
16036 KB |
Output is correct |
33 |
Correct |
0 ms |
256 KB |
Output is correct |
34 |
Correct |
2117 ms |
16016 KB |
Output is correct |
35 |
Correct |
2133 ms |
15988 KB |
Output is correct |
36 |
Correct |
2133 ms |
16024 KB |
Output is correct |
37 |
Correct |
2178 ms |
16060 KB |
Output is correct |
38 |
Correct |
0 ms |
256 KB |
Output is correct |
39 |
Correct |
210 ms |
1912 KB |
Output is correct |
40 |
Correct |
210 ms |
1912 KB |
Output is correct |
41 |
Correct |
210 ms |
1912 KB |
Output is correct |
42 |
Correct |
210 ms |
1912 KB |
Output is correct |
43 |
Correct |
209 ms |
1912 KB |
Output is correct |
44 |
Correct |
212 ms |
1912 KB |
Output is correct |
45 |
Correct |
207 ms |
1912 KB |
Output is correct |
46 |
Correct |
211 ms |
1916 KB |
Output is correct |
47 |
Correct |
211 ms |
1916 KB |
Output is correct |
48 |
Correct |
214 ms |
1912 KB |
Output is correct |
49 |
Correct |
213 ms |
1916 KB |
Output is correct |
50 |
Correct |
214 ms |
1912 KB |
Output is correct |
51 |
Correct |
2095 ms |
16044 KB |
Output is correct |
52 |
Correct |
2074 ms |
16120 KB |
Output is correct |
53 |
Correct |
2146 ms |
15944 KB |
Output is correct |
54 |
Correct |
215 ms |
1912 KB |
Output is correct |
55 |
Correct |
209 ms |
1912 KB |
Output is correct |
56 |
Correct |
704 ms |
5752 KB |
Output is correct |
57 |
Correct |
0 ms |
256 KB |
Output is correct |
58 |
Correct |
209 ms |
2040 KB |
Output is correct |
59 |
Correct |
233 ms |
1912 KB |
Output is correct |
60 |
Correct |
2305 ms |
15992 KB |
Output is correct |
61 |
Correct |
222 ms |
2040 KB |
Output is correct |
62 |
Correct |
215 ms |
2040 KB |
Output is correct |
63 |
Correct |
208 ms |
1912 KB |
Output is correct |
64 |
Correct |
214 ms |
1884 KB |
Output is correct |
65 |
Correct |
221 ms |
1928 KB |
Output is correct |
66 |
Correct |
210 ms |
1912 KB |
Output is correct |
67 |
Correct |
213 ms |
1912 KB |
Output is correct |
68 |
Correct |
207 ms |
1912 KB |
Output is correct |
69 |
Correct |
213 ms |
1912 KB |
Output is correct |
70 |
Correct |
2139 ms |
15944 KB |
Output is correct |
71 |
Correct |
215 ms |
1912 KB |
Output is correct |
72 |
Correct |
2101 ms |
16120 KB |
Output is correct |
73 |
Correct |
2074 ms |
16032 KB |
Output is correct |
74 |
Correct |
0 ms |
256 KB |
Output is correct |
75 |
Correct |
0 ms |
256 KB |
Output is correct |
76 |
Correct |
1 ms |
256 KB |
Output is correct |
77 |
Correct |
0 ms |
256 KB |
Output is correct |
78 |
Correct |
1 ms |
256 KB |
Output is correct |
79 |
Correct |
22 ms |
512 KB |
Output is correct |
80 |
Correct |
2230 ms |
16168 KB |
Output is correct |
81 |
Correct |
2156 ms |
15992 KB |
Output is correct |
82 |
Correct |
2181 ms |
16096 KB |
Output is correct |
83 |
Correct |
2156 ms |
16024 KB |
Output is correct |
84 |
Correct |
2265 ms |
16216 KB |
Output is correct |
85 |
Correct |
2147 ms |
16000 KB |
Output is correct |
86 |
Correct |
689 ms |
5624 KB |
Output is correct |
87 |
Correct |
1 ms |
256 KB |
Output is correct |