#include<bits/stdc++.h>
using namespace std;
#define all(x) x.begin() , x.end()
#define sze(x) (ll)(x.size())
typedef long long ll;
typedef pair<ll , ll> pll;
const ll maxn = 1e6 + 16 , inf = 2e18;
vector<pll> v;
int main(){
ios_base::sync_with_stdio(false); cout.tie(0); cin.tie(0);
ll n , a , b , h;
cin>>n>>a>>b;
__int128_t q = (__int128_t)1 * a * b / __gcd(a , b + 1);
h = min((__int128_t)(inf) , q);
for(ll i = 0 ; i < n ; i++){
ll l , r;
cin>>l>>r; r++;
if(r - l >= h){
cout<<h<<'\n';
return 0;
}
l %= h;
r %= h;
v.push_back({l , 1});
v.push_back({r , -1});
if(r < l){
v.push_back({0 , 1});
v.push_back({h , -1});
}
}
sort(all(v));
ll pr = 0 , cnt = 0 , ans = 0;
ll vs = sze(v);
for(ll i = 0 ; i < vs ; i++){
ll cur = v[i].first;
ans += (cnt > 0) * (cur - pr);
pr = cur;
cnt += v[i].second;
}
cout<<ans<<'\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
7 ms |
1232 KB |
Output is correct |
3 |
Correct |
7 ms |
1232 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
316 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
8 ms |
1232 KB |
Output is correct |
17 |
Correct |
72 ms |
5176 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Correct |
421 ms |
33296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
629 ms |
33860 KB |
Output is correct |
3 |
Correct |
678 ms |
34008 KB |
Output is correct |
4 |
Correct |
641 ms |
33936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
629 ms |
33860 KB |
Output is correct |
3 |
Correct |
678 ms |
34008 KB |
Output is correct |
4 |
Correct |
641 ms |
33936 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
664 ms |
34012 KB |
Output is correct |
7 |
Correct |
622 ms |
33988 KB |
Output is correct |
8 |
Correct |
625 ms |
33916 KB |
Output is correct |
9 |
Correct |
723 ms |
34068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
629 ms |
33860 KB |
Output is correct |
3 |
Correct |
678 ms |
34008 KB |
Output is correct |
4 |
Correct |
641 ms |
33936 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
58 ms |
4668 KB |
Output is correct |
7 |
Correct |
62 ms |
4652 KB |
Output is correct |
8 |
Correct |
60 ms |
5064 KB |
Output is correct |
9 |
Correct |
62 ms |
5180 KB |
Output is correct |
10 |
Correct |
63 ms |
4624 KB |
Output is correct |
11 |
Correct |
66 ms |
4620 KB |
Output is correct |
12 |
Correct |
73 ms |
4796 KB |
Output is correct |
13 |
Correct |
65 ms |
4780 KB |
Output is correct |
14 |
Correct |
61 ms |
4900 KB |
Output is correct |
15 |
Correct |
69 ms |
4668 KB |
Output is correct |
16 |
Correct |
70 ms |
5112 KB |
Output is correct |
17 |
Correct |
68 ms |
5260 KB |
Output is correct |
18 |
Correct |
656 ms |
34000 KB |
Output is correct |
19 |
Correct |
610 ms |
33936 KB |
Output is correct |
20 |
Correct |
733 ms |
34132 KB |
Output is correct |
21 |
Correct |
72 ms |
5192 KB |
Output is correct |
22 |
Correct |
55 ms |
5188 KB |
Output is correct |
23 |
Correct |
187 ms |
17564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
76 ms |
4728 KB |
Output is correct |
3 |
Correct |
70 ms |
4768 KB |
Output is correct |
4 |
Correct |
779 ms |
33968 KB |
Output is correct |
5 |
Correct |
67 ms |
4664 KB |
Output is correct |
6 |
Correct |
67 ms |
4588 KB |
Output is correct |
7 |
Correct |
67 ms |
4620 KB |
Output is correct |
8 |
Correct |
70 ms |
4664 KB |
Output is correct |
9 |
Correct |
66 ms |
4820 KB |
Output is correct |
10 |
Correct |
72 ms |
4748 KB |
Output is correct |
11 |
Correct |
66 ms |
4716 KB |
Output is correct |
12 |
Correct |
71 ms |
4668 KB |
Output is correct |
13 |
Correct |
78 ms |
4900 KB |
Output is correct |
14 |
Correct |
712 ms |
34108 KB |
Output is correct |
15 |
Correct |
72 ms |
5180 KB |
Output is correct |
16 |
Correct |
602 ms |
33804 KB |
Output is correct |
17 |
Correct |
618 ms |
33772 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
7 ms |
1232 KB |
Output is correct |
3 |
Correct |
7 ms |
1232 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
316 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
8 ms |
1232 KB |
Output is correct |
17 |
Correct |
72 ms |
5176 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
0 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
2 ms |
332 KB |
Output is correct |
28 |
Correct |
421 ms |
33296 KB |
Output is correct |
29 |
Correct |
0 ms |
204 KB |
Output is correct |
30 |
Correct |
629 ms |
33860 KB |
Output is correct |
31 |
Correct |
678 ms |
34008 KB |
Output is correct |
32 |
Correct |
641 ms |
33936 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
664 ms |
34012 KB |
Output is correct |
35 |
Correct |
622 ms |
33988 KB |
Output is correct |
36 |
Correct |
625 ms |
33916 KB |
Output is correct |
37 |
Correct |
723 ms |
34068 KB |
Output is correct |
38 |
Correct |
0 ms |
204 KB |
Output is correct |
39 |
Correct |
58 ms |
4668 KB |
Output is correct |
40 |
Correct |
62 ms |
4652 KB |
Output is correct |
41 |
Correct |
60 ms |
5064 KB |
Output is correct |
42 |
Correct |
62 ms |
5180 KB |
Output is correct |
43 |
Correct |
63 ms |
4624 KB |
Output is correct |
44 |
Correct |
66 ms |
4620 KB |
Output is correct |
45 |
Correct |
73 ms |
4796 KB |
Output is correct |
46 |
Correct |
65 ms |
4780 KB |
Output is correct |
47 |
Correct |
61 ms |
4900 KB |
Output is correct |
48 |
Correct |
69 ms |
4668 KB |
Output is correct |
49 |
Correct |
70 ms |
5112 KB |
Output is correct |
50 |
Correct |
68 ms |
5260 KB |
Output is correct |
51 |
Correct |
656 ms |
34000 KB |
Output is correct |
52 |
Correct |
610 ms |
33936 KB |
Output is correct |
53 |
Correct |
733 ms |
34132 KB |
Output is correct |
54 |
Correct |
72 ms |
5192 KB |
Output is correct |
55 |
Correct |
55 ms |
5188 KB |
Output is correct |
56 |
Correct |
187 ms |
17564 KB |
Output is correct |
57 |
Correct |
1 ms |
204 KB |
Output is correct |
58 |
Correct |
76 ms |
4728 KB |
Output is correct |
59 |
Correct |
70 ms |
4768 KB |
Output is correct |
60 |
Correct |
779 ms |
33968 KB |
Output is correct |
61 |
Correct |
67 ms |
4664 KB |
Output is correct |
62 |
Correct |
67 ms |
4588 KB |
Output is correct |
63 |
Correct |
67 ms |
4620 KB |
Output is correct |
64 |
Correct |
70 ms |
4664 KB |
Output is correct |
65 |
Correct |
66 ms |
4820 KB |
Output is correct |
66 |
Correct |
72 ms |
4748 KB |
Output is correct |
67 |
Correct |
66 ms |
4716 KB |
Output is correct |
68 |
Correct |
71 ms |
4668 KB |
Output is correct |
69 |
Correct |
78 ms |
4900 KB |
Output is correct |
70 |
Correct |
712 ms |
34108 KB |
Output is correct |
71 |
Correct |
72 ms |
5180 KB |
Output is correct |
72 |
Correct |
602 ms |
33804 KB |
Output is correct |
73 |
Correct |
618 ms |
33772 KB |
Output is correct |
74 |
Correct |
1 ms |
204 KB |
Output is correct |
75 |
Correct |
1 ms |
312 KB |
Output is correct |
76 |
Correct |
1 ms |
204 KB |
Output is correct |
77 |
Correct |
1 ms |
204 KB |
Output is correct |
78 |
Correct |
1 ms |
204 KB |
Output is correct |
79 |
Correct |
6 ms |
1232 KB |
Output is correct |
80 |
Correct |
746 ms |
33796 KB |
Output is correct |
81 |
Correct |
748 ms |
33808 KB |
Output is correct |
82 |
Correct |
722 ms |
33684 KB |
Output is correct |
83 |
Correct |
697 ms |
33672 KB |
Output is correct |
84 |
Correct |
716 ms |
33728 KB |
Output is correct |
85 |
Correct |
703 ms |
33640 KB |
Output is correct |
86 |
Correct |
171 ms |
17320 KB |
Output is correct |
87 |
Correct |
1 ms |
204 KB |
Output is correct |