#include <bits/stdc++.h>
#define ll long long
#define db long double
#define N 4000002
#define II pair <ll,ll>
#define fst first
#define snd second
using namespace std;
ll n,a,b,l,r,m,i,x;
II c[N];
void add(ll l,ll r) { c[++m]={ l,1 }; c[++m]={ r,-1 }; }
const ll oo=round(1e18);
ll cal()
{
ll bb=(b%a+1)%a,x=a/__gcd(bb,a);
if(x>oo/b) return oo+1;
return x*b;
}
int main()
{
// freopen("ntu.inp","r",stdin);
//freopen("ntu.out","w",stdout);
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin>>n>>a>>b;
x=cal();
for(i=1;i<=n;i++)
{
cin>>l>>r;
if(r-l+1>=x) { cout<<x; return 0; }
l=l%x; r=r%x;
if(l<=r) add(l,r);
else add(l,x-1),add(0,r);
}
sort(c+1,c+m+1);
c[0]={ -1,1 };
ll cnt=0,res=0;
for(i=1;i<=m;i++)
{
if(c[i].fst>c[i-1].fst)
{
if(cnt>0) res+=c[i].fst-c[i-1].fst;
else res++;
}
cnt+=c[i].snd;
}
cout<<res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
324 KB |
Output is correct |
2 |
Correct |
5 ms |
980 KB |
Output is correct |
3 |
Correct |
6 ms |
980 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
6 ms |
980 KB |
Output is correct |
17 |
Correct |
57 ms |
7140 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
326 ms |
56824 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
463 ms |
47212 KB |
Output is correct |
3 |
Correct |
489 ms |
47188 KB |
Output is correct |
4 |
Correct |
455 ms |
68836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
463 ms |
47212 KB |
Output is correct |
3 |
Correct |
489 ms |
47188 KB |
Output is correct |
4 |
Correct |
455 ms |
68836 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
469 ms |
68812 KB |
Output is correct |
7 |
Correct |
461 ms |
68832 KB |
Output is correct |
8 |
Correct |
476 ms |
68940 KB |
Output is correct |
9 |
Correct |
544 ms |
68820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
463 ms |
47212 KB |
Output is correct |
3 |
Correct |
489 ms |
47188 KB |
Output is correct |
4 |
Correct |
455 ms |
68836 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
48 ms |
7160 KB |
Output is correct |
7 |
Correct |
46 ms |
7132 KB |
Output is correct |
8 |
Correct |
45 ms |
7248 KB |
Output is correct |
9 |
Correct |
47 ms |
7048 KB |
Output is correct |
10 |
Correct |
46 ms |
7096 KB |
Output is correct |
11 |
Correct |
48 ms |
7124 KB |
Output is correct |
12 |
Correct |
44 ms |
7244 KB |
Output is correct |
13 |
Correct |
49 ms |
7148 KB |
Output is correct |
14 |
Correct |
44 ms |
7120 KB |
Output is correct |
15 |
Correct |
50 ms |
7104 KB |
Output is correct |
16 |
Correct |
51 ms |
7104 KB |
Output is correct |
17 |
Correct |
44 ms |
7108 KB |
Output is correct |
18 |
Correct |
474 ms |
68812 KB |
Output is correct |
19 |
Correct |
449 ms |
68812 KB |
Output is correct |
20 |
Correct |
550 ms |
68812 KB |
Output is correct |
21 |
Correct |
53 ms |
7104 KB |
Output is correct |
22 |
Correct |
40 ms |
7076 KB |
Output is correct |
23 |
Correct |
130 ms |
23632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
57 ms |
7152 KB |
Output is correct |
3 |
Correct |
56 ms |
7124 KB |
Output is correct |
4 |
Correct |
584 ms |
47276 KB |
Output is correct |
5 |
Correct |
50 ms |
7084 KB |
Output is correct |
6 |
Correct |
60 ms |
7244 KB |
Output is correct |
7 |
Correct |
51 ms |
7152 KB |
Output is correct |
8 |
Correct |
52 ms |
7104 KB |
Output is correct |
9 |
Correct |
49 ms |
7032 KB |
Output is correct |
10 |
Correct |
53 ms |
7092 KB |
Output is correct |
11 |
Correct |
51 ms |
7056 KB |
Output is correct |
12 |
Correct |
46 ms |
7116 KB |
Output is correct |
13 |
Correct |
51 ms |
7116 KB |
Output is correct |
14 |
Correct |
540 ms |
47192 KB |
Output is correct |
15 |
Correct |
54 ms |
7116 KB |
Output is correct |
16 |
Correct |
449 ms |
68956 KB |
Output is correct |
17 |
Correct |
466 ms |
68932 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
324 KB |
Output is correct |
2 |
Correct |
5 ms |
980 KB |
Output is correct |
3 |
Correct |
6 ms |
980 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
6 ms |
980 KB |
Output is correct |
17 |
Correct |
57 ms |
7140 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
328 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
326 ms |
56824 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
463 ms |
47212 KB |
Output is correct |
31 |
Correct |
489 ms |
47188 KB |
Output is correct |
32 |
Correct |
455 ms |
68836 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
469 ms |
68812 KB |
Output is correct |
35 |
Correct |
461 ms |
68832 KB |
Output is correct |
36 |
Correct |
476 ms |
68940 KB |
Output is correct |
37 |
Correct |
544 ms |
68820 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
48 ms |
7160 KB |
Output is correct |
40 |
Correct |
46 ms |
7132 KB |
Output is correct |
41 |
Correct |
45 ms |
7248 KB |
Output is correct |
42 |
Correct |
47 ms |
7048 KB |
Output is correct |
43 |
Correct |
46 ms |
7096 KB |
Output is correct |
44 |
Correct |
48 ms |
7124 KB |
Output is correct |
45 |
Correct |
44 ms |
7244 KB |
Output is correct |
46 |
Correct |
49 ms |
7148 KB |
Output is correct |
47 |
Correct |
44 ms |
7120 KB |
Output is correct |
48 |
Correct |
50 ms |
7104 KB |
Output is correct |
49 |
Correct |
51 ms |
7104 KB |
Output is correct |
50 |
Correct |
44 ms |
7108 KB |
Output is correct |
51 |
Correct |
474 ms |
68812 KB |
Output is correct |
52 |
Correct |
449 ms |
68812 KB |
Output is correct |
53 |
Correct |
550 ms |
68812 KB |
Output is correct |
54 |
Correct |
53 ms |
7104 KB |
Output is correct |
55 |
Correct |
40 ms |
7076 KB |
Output is correct |
56 |
Correct |
130 ms |
23632 KB |
Output is correct |
57 |
Correct |
1 ms |
212 KB |
Output is correct |
58 |
Correct |
57 ms |
7152 KB |
Output is correct |
59 |
Correct |
56 ms |
7124 KB |
Output is correct |
60 |
Correct |
584 ms |
47276 KB |
Output is correct |
61 |
Correct |
50 ms |
7084 KB |
Output is correct |
62 |
Correct |
60 ms |
7244 KB |
Output is correct |
63 |
Correct |
51 ms |
7152 KB |
Output is correct |
64 |
Correct |
52 ms |
7104 KB |
Output is correct |
65 |
Correct |
49 ms |
7032 KB |
Output is correct |
66 |
Correct |
53 ms |
7092 KB |
Output is correct |
67 |
Correct |
51 ms |
7056 KB |
Output is correct |
68 |
Correct |
46 ms |
7116 KB |
Output is correct |
69 |
Correct |
51 ms |
7116 KB |
Output is correct |
70 |
Correct |
540 ms |
47192 KB |
Output is correct |
71 |
Correct |
54 ms |
7116 KB |
Output is correct |
72 |
Correct |
449 ms |
68956 KB |
Output is correct |
73 |
Correct |
466 ms |
68932 KB |
Output is correct |
74 |
Correct |
0 ms |
212 KB |
Output is correct |
75 |
Correct |
1 ms |
212 KB |
Output is correct |
76 |
Correct |
0 ms |
212 KB |
Output is correct |
77 |
Correct |
1 ms |
212 KB |
Output is correct |
78 |
Correct |
1 ms |
212 KB |
Output is correct |
79 |
Correct |
4 ms |
920 KB |
Output is correct |
80 |
Correct |
580 ms |
68900 KB |
Output is correct |
81 |
Correct |
586 ms |
68912 KB |
Output is correct |
82 |
Correct |
555 ms |
68916 KB |
Output is correct |
83 |
Correct |
561 ms |
68812 KB |
Output is correct |
84 |
Correct |
552 ms |
68888 KB |
Output is correct |
85 |
Correct |
541 ms |
68768 KB |
Output is correct |
86 |
Correct |
129 ms |
23480 KB |
Output is correct |
87 |
Correct |
0 ms |
212 KB |
Output is correct |