#include <bits/stdc++.h>
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long int ll;
typedef long double ldb;
ll gcd(ll x,ll y){if(!x||!y) return x+y; return x%y==0?y:gcd(y,x%y);}
ll n, A, B, inf=2e18, ans;
pair<ll, ll> wow[2111111];
int main(void)
{
fio; ll i, j, u, v, cnt=0;
cin>>n>>A>>B; ll g=gcd(A, B+1);
__int128 cc=(A/g); cc=cc*B;
for(i=1 ; i<=n ; i++)
{
cin>>u>>v;
if(cc>=inf) { wow[++cnt]=make_pair(u, v); continue; }
if(v-u+1>=cc) { cout<<(long long int)(cc); return 0; }
u=(ll)(u%cc); v=(ll)(v%cc);
if(u<=v) wow[++cnt]=make_pair(u, v);
if(u>v)
{
wow[++cnt]=make_pair(u, (ll)cc-1LL);
wow[++cnt]=make_pair(0LL, v);
}
}
sort(wow+1, wow+cnt+1);
for(i=1 ; i<=cnt ; i++)
{
j=i; ll rng=wow[i].second;
while(j<=cnt && wow[j].first<=rng)
{ rng=max(rng, wow[j].second); j++; }
j--; ans+=(rng-wow[i].first+1); i=j;
}
cout<<ans; return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
10 ms |
1016 KB |
Output is correct |
3 |
Correct |
10 ms |
888 KB |
Output is correct |
4 |
Correct |
5 ms |
504 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
380 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
10 ms |
888 KB |
Output is correct |
17 |
Correct |
62 ms |
5624 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
380 ms |
20088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
517 ms |
16376 KB |
Output is correct |
3 |
Correct |
523 ms |
16412 KB |
Output is correct |
4 |
Correct |
504 ms |
20216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
517 ms |
16376 KB |
Output is correct |
3 |
Correct |
523 ms |
16412 KB |
Output is correct |
4 |
Correct |
504 ms |
20216 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
519 ms |
20060 KB |
Output is correct |
7 |
Correct |
521 ms |
20216 KB |
Output is correct |
8 |
Correct |
499 ms |
20084 KB |
Output is correct |
9 |
Correct |
568 ms |
20088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
517 ms |
16376 KB |
Output is correct |
3 |
Correct |
523 ms |
16412 KB |
Output is correct |
4 |
Correct |
504 ms |
20216 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
56 ms |
5624 KB |
Output is correct |
7 |
Correct |
58 ms |
5596 KB |
Output is correct |
8 |
Correct |
56 ms |
5624 KB |
Output is correct |
9 |
Correct |
56 ms |
5624 KB |
Output is correct |
10 |
Correct |
54 ms |
5624 KB |
Output is correct |
11 |
Correct |
56 ms |
5624 KB |
Output is correct |
12 |
Correct |
55 ms |
5624 KB |
Output is correct |
13 |
Correct |
60 ms |
5624 KB |
Output is correct |
14 |
Correct |
56 ms |
5624 KB |
Output is correct |
15 |
Correct |
70 ms |
5624 KB |
Output is correct |
16 |
Correct |
59 ms |
5624 KB |
Output is correct |
17 |
Correct |
58 ms |
5628 KB |
Output is correct |
18 |
Correct |
500 ms |
19832 KB |
Output is correct |
19 |
Correct |
509 ms |
19448 KB |
Output is correct |
20 |
Correct |
575 ms |
19320 KB |
Output is correct |
21 |
Correct |
61 ms |
5240 KB |
Output is correct |
22 |
Correct |
53 ms |
4984 KB |
Output is correct |
23 |
Correct |
162 ms |
8568 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
59 ms |
4088 KB |
Output is correct |
3 |
Correct |
62 ms |
3960 KB |
Output is correct |
4 |
Correct |
613 ms |
18080 KB |
Output is correct |
5 |
Correct |
58 ms |
3832 KB |
Output is correct |
6 |
Correct |
61 ms |
3832 KB |
Output is correct |
7 |
Correct |
59 ms |
3320 KB |
Output is correct |
8 |
Correct |
60 ms |
3268 KB |
Output is correct |
9 |
Correct |
58 ms |
3320 KB |
Output is correct |
10 |
Correct |
58 ms |
3192 KB |
Output is correct |
11 |
Correct |
58 ms |
3192 KB |
Output is correct |
12 |
Correct |
57 ms |
3320 KB |
Output is correct |
13 |
Correct |
60 ms |
3064 KB |
Output is correct |
14 |
Correct |
561 ms |
16888 KB |
Output is correct |
15 |
Correct |
61 ms |
2680 KB |
Output is correct |
16 |
Correct |
506 ms |
16692 KB |
Output is correct |
17 |
Correct |
525 ms |
16352 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
10 ms |
1016 KB |
Output is correct |
3 |
Correct |
10 ms |
888 KB |
Output is correct |
4 |
Correct |
5 ms |
504 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
380 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
10 ms |
888 KB |
Output is correct |
17 |
Correct |
62 ms |
5624 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
6 ms |
376 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
5 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
25 |
Correct |
5 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
376 KB |
Output is correct |
27 |
Correct |
5 ms |
376 KB |
Output is correct |
28 |
Correct |
380 ms |
20088 KB |
Output is correct |
29 |
Correct |
5 ms |
376 KB |
Output is correct |
30 |
Correct |
517 ms |
16376 KB |
Output is correct |
31 |
Correct |
523 ms |
16412 KB |
Output is correct |
32 |
Correct |
504 ms |
20216 KB |
Output is correct |
33 |
Correct |
5 ms |
376 KB |
Output is correct |
34 |
Correct |
519 ms |
20060 KB |
Output is correct |
35 |
Correct |
521 ms |
20216 KB |
Output is correct |
36 |
Correct |
499 ms |
20084 KB |
Output is correct |
37 |
Correct |
568 ms |
20088 KB |
Output is correct |
38 |
Correct |
5 ms |
376 KB |
Output is correct |
39 |
Correct |
56 ms |
5624 KB |
Output is correct |
40 |
Correct |
58 ms |
5596 KB |
Output is correct |
41 |
Correct |
56 ms |
5624 KB |
Output is correct |
42 |
Correct |
56 ms |
5624 KB |
Output is correct |
43 |
Correct |
54 ms |
5624 KB |
Output is correct |
44 |
Correct |
56 ms |
5624 KB |
Output is correct |
45 |
Correct |
55 ms |
5624 KB |
Output is correct |
46 |
Correct |
60 ms |
5624 KB |
Output is correct |
47 |
Correct |
56 ms |
5624 KB |
Output is correct |
48 |
Correct |
70 ms |
5624 KB |
Output is correct |
49 |
Correct |
59 ms |
5624 KB |
Output is correct |
50 |
Correct |
58 ms |
5628 KB |
Output is correct |
51 |
Correct |
500 ms |
19832 KB |
Output is correct |
52 |
Correct |
509 ms |
19448 KB |
Output is correct |
53 |
Correct |
575 ms |
19320 KB |
Output is correct |
54 |
Correct |
61 ms |
5240 KB |
Output is correct |
55 |
Correct |
53 ms |
4984 KB |
Output is correct |
56 |
Correct |
162 ms |
8568 KB |
Output is correct |
57 |
Correct |
5 ms |
376 KB |
Output is correct |
58 |
Correct |
59 ms |
4088 KB |
Output is correct |
59 |
Correct |
62 ms |
3960 KB |
Output is correct |
60 |
Correct |
613 ms |
18080 KB |
Output is correct |
61 |
Correct |
58 ms |
3832 KB |
Output is correct |
62 |
Correct |
61 ms |
3832 KB |
Output is correct |
63 |
Correct |
59 ms |
3320 KB |
Output is correct |
64 |
Correct |
60 ms |
3268 KB |
Output is correct |
65 |
Correct |
58 ms |
3320 KB |
Output is correct |
66 |
Correct |
58 ms |
3192 KB |
Output is correct |
67 |
Correct |
58 ms |
3192 KB |
Output is correct |
68 |
Correct |
57 ms |
3320 KB |
Output is correct |
69 |
Correct |
60 ms |
3064 KB |
Output is correct |
70 |
Correct |
561 ms |
16888 KB |
Output is correct |
71 |
Correct |
61 ms |
2680 KB |
Output is correct |
72 |
Correct |
506 ms |
16692 KB |
Output is correct |
73 |
Correct |
525 ms |
16352 KB |
Output is correct |
74 |
Correct |
5 ms |
376 KB |
Output is correct |
75 |
Correct |
5 ms |
376 KB |
Output is correct |
76 |
Correct |
5 ms |
376 KB |
Output is correct |
77 |
Correct |
5 ms |
376 KB |
Output is correct |
78 |
Correct |
5 ms |
376 KB |
Output is correct |
79 |
Correct |
10 ms |
888 KB |
Output is correct |
80 |
Correct |
619 ms |
23416 KB |
Output is correct |
81 |
Correct |
615 ms |
23160 KB |
Output is correct |
82 |
Correct |
574 ms |
23416 KB |
Output is correct |
83 |
Correct |
554 ms |
23288 KB |
Output is correct |
84 |
Correct |
581 ms |
23416 KB |
Output is correct |
85 |
Correct |
573 ms |
23576 KB |
Output is correct |
86 |
Correct |
170 ms |
18168 KB |
Output is correct |
87 |
Correct |
5 ms |
376 KB |
Output is correct |