#include <bits/stdc++.h>
using namespace std;
long long lim;
int n;
long long a,b;
vector<pair<long long,long long>>vec;
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n;
cin>>a>>b;
long long v=a/__gcd(a,b+1);
if(v<=2e18/b)lim=v*b;
else lim=2e18;
for(int i=1;i<=n;i++)
{
long long l,r;cin>>l>>r;
if(r-l+1>=lim){cout<<lim;return 0;}
l=l%lim;r=r%lim;
if(l<=r)vec.push_back({l,r});
else {vec.push_back({0,r});vec.push_back({l,lim-1});}
}
sort(vec.begin(),vec.end());
long long dem=0;
long long r=-2,l=-1;
for(auto v:vec)
{
if(r<v.first){dem+=r-l+1;l=v.first;r=v.second;}
else
r=max(r,v.second);
}
dem+=r-l+1;
cout<<dem;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
4 ms |
600 KB |
Output is correct |
3 |
Correct |
5 ms |
688 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
41 ms |
2472 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 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 |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
314 ms |
16796 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
379 ms |
16832 KB |
Output is correct |
3 |
Correct |
367 ms |
16752 KB |
Output is correct |
4 |
Correct |
365 ms |
16860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
379 ms |
16832 KB |
Output is correct |
3 |
Correct |
367 ms |
16752 KB |
Output is correct |
4 |
Correct |
365 ms |
16860 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
385 ms |
16800 KB |
Output is correct |
7 |
Correct |
374 ms |
16832 KB |
Output is correct |
8 |
Correct |
364 ms |
16816 KB |
Output is correct |
9 |
Correct |
390 ms |
16764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
379 ms |
16832 KB |
Output is correct |
3 |
Correct |
367 ms |
16752 KB |
Output is correct |
4 |
Correct |
365 ms |
16860 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
37 ms |
2488 KB |
Output is correct |
7 |
Correct |
39 ms |
2436 KB |
Output is correct |
8 |
Correct |
43 ms |
2544 KB |
Output is correct |
9 |
Correct |
36 ms |
2376 KB |
Output is correct |
10 |
Correct |
37 ms |
2512 KB |
Output is correct |
11 |
Correct |
38 ms |
2504 KB |
Output is correct |
12 |
Correct |
36 ms |
2412 KB |
Output is correct |
13 |
Correct |
39 ms |
2436 KB |
Output is correct |
14 |
Correct |
37 ms |
2452 KB |
Output is correct |
15 |
Correct |
39 ms |
2512 KB |
Output is correct |
16 |
Correct |
38 ms |
2512 KB |
Output is correct |
17 |
Correct |
41 ms |
2584 KB |
Output is correct |
18 |
Correct |
378 ms |
16832 KB |
Output is correct |
19 |
Correct |
363 ms |
16904 KB |
Output is correct |
20 |
Correct |
405 ms |
16784 KB |
Output is correct |
21 |
Correct |
39 ms |
2448 KB |
Output is correct |
22 |
Correct |
35 ms |
2432 KB |
Output is correct |
23 |
Correct |
114 ms |
8620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
38 ms |
2512 KB |
Output is correct |
3 |
Correct |
39 ms |
2392 KB |
Output is correct |
4 |
Correct |
445 ms |
16832 KB |
Output is correct |
5 |
Correct |
38 ms |
2512 KB |
Output is correct |
6 |
Correct |
40 ms |
2404 KB |
Output is correct |
7 |
Correct |
38 ms |
2512 KB |
Output is correct |
8 |
Correct |
40 ms |
2504 KB |
Output is correct |
9 |
Correct |
39 ms |
2504 KB |
Output is correct |
10 |
Correct |
41 ms |
2476 KB |
Output is correct |
11 |
Correct |
41 ms |
2420 KB |
Output is correct |
12 |
Correct |
40 ms |
2404 KB |
Output is correct |
13 |
Correct |
41 ms |
2488 KB |
Output is correct |
14 |
Correct |
432 ms |
16816 KB |
Output is correct |
15 |
Correct |
39 ms |
2512 KB |
Output is correct |
16 |
Correct |
374 ms |
16940 KB |
Output is correct |
17 |
Correct |
374 ms |
16776 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
4 ms |
600 KB |
Output is correct |
3 |
Correct |
5 ms |
688 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
41 ms |
2472 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 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 |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
314 ms |
16796 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
379 ms |
16832 KB |
Output is correct |
31 |
Correct |
367 ms |
16752 KB |
Output is correct |
32 |
Correct |
365 ms |
16860 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
385 ms |
16800 KB |
Output is correct |
35 |
Correct |
374 ms |
16832 KB |
Output is correct |
36 |
Correct |
364 ms |
16816 KB |
Output is correct |
37 |
Correct |
390 ms |
16764 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
37 ms |
2488 KB |
Output is correct |
40 |
Correct |
39 ms |
2436 KB |
Output is correct |
41 |
Correct |
43 ms |
2544 KB |
Output is correct |
42 |
Correct |
36 ms |
2376 KB |
Output is correct |
43 |
Correct |
37 ms |
2512 KB |
Output is correct |
44 |
Correct |
38 ms |
2504 KB |
Output is correct |
45 |
Correct |
36 ms |
2412 KB |
Output is correct |
46 |
Correct |
39 ms |
2436 KB |
Output is correct |
47 |
Correct |
37 ms |
2452 KB |
Output is correct |
48 |
Correct |
39 ms |
2512 KB |
Output is correct |
49 |
Correct |
38 ms |
2512 KB |
Output is correct |
50 |
Correct |
41 ms |
2584 KB |
Output is correct |
51 |
Correct |
378 ms |
16832 KB |
Output is correct |
52 |
Correct |
363 ms |
16904 KB |
Output is correct |
53 |
Correct |
405 ms |
16784 KB |
Output is correct |
54 |
Correct |
39 ms |
2448 KB |
Output is correct |
55 |
Correct |
35 ms |
2432 KB |
Output is correct |
56 |
Correct |
114 ms |
8620 KB |
Output is correct |
57 |
Correct |
0 ms |
212 KB |
Output is correct |
58 |
Correct |
38 ms |
2512 KB |
Output is correct |
59 |
Correct |
39 ms |
2392 KB |
Output is correct |
60 |
Correct |
445 ms |
16832 KB |
Output is correct |
61 |
Correct |
38 ms |
2512 KB |
Output is correct |
62 |
Correct |
40 ms |
2404 KB |
Output is correct |
63 |
Correct |
38 ms |
2512 KB |
Output is correct |
64 |
Correct |
40 ms |
2504 KB |
Output is correct |
65 |
Correct |
39 ms |
2504 KB |
Output is correct |
66 |
Correct |
41 ms |
2476 KB |
Output is correct |
67 |
Correct |
41 ms |
2420 KB |
Output is correct |
68 |
Correct |
40 ms |
2404 KB |
Output is correct |
69 |
Correct |
41 ms |
2488 KB |
Output is correct |
70 |
Correct |
432 ms |
16816 KB |
Output is correct |
71 |
Correct |
39 ms |
2512 KB |
Output is correct |
72 |
Correct |
374 ms |
16940 KB |
Output is correct |
73 |
Correct |
374 ms |
16776 KB |
Output is correct |
74 |
Correct |
0 ms |
212 KB |
Output is correct |
75 |
Correct |
1 ms |
212 KB |
Output is correct |
76 |
Correct |
1 ms |
212 KB |
Output is correct |
77 |
Correct |
1 ms |
212 KB |
Output is correct |
78 |
Correct |
1 ms |
324 KB |
Output is correct |
79 |
Correct |
5 ms |
1012 KB |
Output is correct |
80 |
Correct |
494 ms |
28756 KB |
Output is correct |
81 |
Correct |
484 ms |
28800 KB |
Output is correct |
82 |
Correct |
447 ms |
28984 KB |
Output is correct |
83 |
Correct |
452 ms |
28780 KB |
Output is correct |
84 |
Correct |
455 ms |
28748 KB |
Output is correct |
85 |
Correct |
408 ms |
28816 KB |
Output is correct |
86 |
Correct |
130 ms |
18088 KB |
Output is correct |
87 |
Correct |
1 ms |
212 KB |
Output is correct |