#include "bits/stdc++.h"
using namespace std;
#define int int64_t
#define pb push_back
using lint=__int128_t;
const int lim=200100;
const int mod=1e9+7;
using pii=pair<int,int>;
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#ifdef Local
freopen(".in","r",stdin);freopen(".out","w",stdout);
#endif
int n,a,b;
cin>>n>>a>>b;
lint cntofdif=a/__gcd(a,(b+1));
cntofdif*=b;
cntofdif=min(cntofdif,lint(2e18));
int all=cntofdif;
//cerr<<all<<"\n";
vector<pii>ranges;
for(int i=0;i<n;i++){
int l,r;
cin>>l>>r;
if(all<=r-l+1){
cout<<all;
return 0;
}
l%=all;
r%=all;
if(l<=r){
ranges.pb({l,r});
//cerr<<"inserted "<<l<<" "<<r<<"\n";
}
else{
//cerr<<"oops "<<l<<" "<<r<<"\n";
ranges.pb({l,all-1});
ranges.pb({0,r});
}
}
sort(ranges.begin(),ranges.end());
int cnt=0,left=-1;
for(auto[f,s]:ranges){
if(left<f){
cnt+=s-f+1;
}else if(left<s){
cnt+=s-left;
}
left=max(left,s);
}
cout<<cnt<<"\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
988 KB |
Output is correct |
3 |
Correct |
3 ms |
736 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
376 KB |
Output is correct |
8 |
Correct |
0 ms |
600 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
736 KB |
Output is correct |
17 |
Correct |
24 ms |
2520 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
360 KB |
Output is correct |
5 |
Correct |
146 ms |
18060 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
214 ms |
16920 KB |
Output is correct |
3 |
Correct |
221 ms |
53808 KB |
Output is correct |
4 |
Correct |
228 ms |
53592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
214 ms |
16920 KB |
Output is correct |
3 |
Correct |
221 ms |
53808 KB |
Output is correct |
4 |
Correct |
228 ms |
53592 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
230 ms |
53396 KB |
Output is correct |
7 |
Correct |
219 ms |
53420 KB |
Output is correct |
8 |
Correct |
218 ms |
53940 KB |
Output is correct |
9 |
Correct |
243 ms |
53940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
214 ms |
16920 KB |
Output is correct |
3 |
Correct |
221 ms |
53808 KB |
Output is correct |
4 |
Correct |
228 ms |
53592 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
25 ms |
5864 KB |
Output is correct |
7 |
Correct |
25 ms |
5844 KB |
Output is correct |
8 |
Correct |
24 ms |
5824 KB |
Output is correct |
9 |
Correct |
23 ms |
5836 KB |
Output is correct |
10 |
Correct |
22 ms |
5836 KB |
Output is correct |
11 |
Correct |
24 ms |
5844 KB |
Output is correct |
12 |
Correct |
23 ms |
5708 KB |
Output is correct |
13 |
Correct |
25 ms |
5648 KB |
Output is correct |
14 |
Correct |
23 ms |
5836 KB |
Output is correct |
15 |
Correct |
27 ms |
5944 KB |
Output is correct |
16 |
Correct |
25 ms |
5652 KB |
Output is correct |
17 |
Correct |
24 ms |
5836 KB |
Output is correct |
18 |
Correct |
222 ms |
53416 KB |
Output is correct |
19 |
Correct |
235 ms |
53424 KB |
Output is correct |
20 |
Correct |
244 ms |
53424 KB |
Output is correct |
21 |
Correct |
24 ms |
5844 KB |
Output is correct |
22 |
Correct |
23 ms |
5836 KB |
Output is correct |
23 |
Correct |
68 ms |
20424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
23 ms |
2520 KB |
Output is correct |
3 |
Correct |
24 ms |
2520 KB |
Output is correct |
4 |
Correct |
260 ms |
54044 KB |
Output is correct |
5 |
Correct |
29 ms |
5836 KB |
Output is correct |
6 |
Correct |
24 ms |
5792 KB |
Output is correct |
7 |
Correct |
29 ms |
5692 KB |
Output is correct |
8 |
Correct |
24 ms |
5744 KB |
Output is correct |
9 |
Correct |
26 ms |
5836 KB |
Output is correct |
10 |
Correct |
26 ms |
5820 KB |
Output is correct |
11 |
Correct |
24 ms |
5844 KB |
Output is correct |
12 |
Correct |
21 ms |
5696 KB |
Output is correct |
13 |
Correct |
24 ms |
5744 KB |
Output is correct |
14 |
Correct |
248 ms |
53940 KB |
Output is correct |
15 |
Correct |
23 ms |
5836 KB |
Output is correct |
16 |
Correct |
225 ms |
53424 KB |
Output is correct |
17 |
Correct |
230 ms |
53356 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
988 KB |
Output is correct |
3 |
Correct |
3 ms |
736 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
376 KB |
Output is correct |
8 |
Correct |
0 ms |
600 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
736 KB |
Output is correct |
17 |
Correct |
24 ms |
2520 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
360 KB |
Output is correct |
28 |
Correct |
146 ms |
18060 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
214 ms |
16920 KB |
Output is correct |
31 |
Correct |
221 ms |
53808 KB |
Output is correct |
32 |
Correct |
228 ms |
53592 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
230 ms |
53396 KB |
Output is correct |
35 |
Correct |
219 ms |
53420 KB |
Output is correct |
36 |
Correct |
218 ms |
53940 KB |
Output is correct |
37 |
Correct |
243 ms |
53940 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
25 ms |
5864 KB |
Output is correct |
40 |
Correct |
25 ms |
5844 KB |
Output is correct |
41 |
Correct |
24 ms |
5824 KB |
Output is correct |
42 |
Correct |
23 ms |
5836 KB |
Output is correct |
43 |
Correct |
22 ms |
5836 KB |
Output is correct |
44 |
Correct |
24 ms |
5844 KB |
Output is correct |
45 |
Correct |
23 ms |
5708 KB |
Output is correct |
46 |
Correct |
25 ms |
5648 KB |
Output is correct |
47 |
Correct |
23 ms |
5836 KB |
Output is correct |
48 |
Correct |
27 ms |
5944 KB |
Output is correct |
49 |
Correct |
25 ms |
5652 KB |
Output is correct |
50 |
Correct |
24 ms |
5836 KB |
Output is correct |
51 |
Correct |
222 ms |
53416 KB |
Output is correct |
52 |
Correct |
235 ms |
53424 KB |
Output is correct |
53 |
Correct |
244 ms |
53424 KB |
Output is correct |
54 |
Correct |
24 ms |
5844 KB |
Output is correct |
55 |
Correct |
23 ms |
5836 KB |
Output is correct |
56 |
Correct |
68 ms |
20424 KB |
Output is correct |
57 |
Correct |
1 ms |
348 KB |
Output is correct |
58 |
Correct |
23 ms |
2520 KB |
Output is correct |
59 |
Correct |
24 ms |
2520 KB |
Output is correct |
60 |
Correct |
260 ms |
54044 KB |
Output is correct |
61 |
Correct |
29 ms |
5836 KB |
Output is correct |
62 |
Correct |
24 ms |
5792 KB |
Output is correct |
63 |
Correct |
29 ms |
5692 KB |
Output is correct |
64 |
Correct |
24 ms |
5744 KB |
Output is correct |
65 |
Correct |
26 ms |
5836 KB |
Output is correct |
66 |
Correct |
26 ms |
5820 KB |
Output is correct |
67 |
Correct |
24 ms |
5844 KB |
Output is correct |
68 |
Correct |
21 ms |
5696 KB |
Output is correct |
69 |
Correct |
24 ms |
5744 KB |
Output is correct |
70 |
Correct |
248 ms |
53940 KB |
Output is correct |
71 |
Correct |
23 ms |
5836 KB |
Output is correct |
72 |
Correct |
225 ms |
53424 KB |
Output is correct |
73 |
Correct |
230 ms |
53356 KB |
Output is correct |
74 |
Correct |
0 ms |
348 KB |
Output is correct |
75 |
Correct |
1 ms |
348 KB |
Output is correct |
76 |
Correct |
0 ms |
348 KB |
Output is correct |
77 |
Correct |
0 ms |
348 KB |
Output is correct |
78 |
Correct |
0 ms |
348 KB |
Output is correct |
79 |
Correct |
2 ms |
1112 KB |
Output is correct |
80 |
Correct |
261 ms |
53412 KB |
Output is correct |
81 |
Correct |
254 ms |
53932 KB |
Output is correct |
82 |
Correct |
280 ms |
52932 KB |
Output is correct |
83 |
Correct |
251 ms |
53184 KB |
Output is correct |
84 |
Correct |
249 ms |
53380 KB |
Output is correct |
85 |
Correct |
247 ms |
53244 KB |
Output is correct |
86 |
Correct |
68 ms |
20416 KB |
Output is correct |
87 |
Correct |
0 ms |
348 KB |
Output is correct |