#include<bits/stdc++.h>
template<class T> inline void read(T &x){
x=0; register char c=getchar(); register bool f=0;
while(!isdigit(c))f^=c=='-',c=getchar();
while(isdigit(c))x=x*10+c-'0',c=getchar(); if(f)x=-x;
}
template<class T> inline T gcd(T n,T m){return m?gcd(m,n%m):n;}
const int N=1e6+10;
int n;
long long A,B,l,r,ans;
std::map<long long,int> sum;
int main(){
#ifdef memset0
freopen("1.in","r",stdin);
#endif
read(n),read(A),read(B);
A/=gcd(A,B+1);
if(A>(long long)(2e18)/B){
for(int i=1;i<=n;i++){
read(l),read(r);
ans+=r-l+1;
}
printf("%lld\n",ans);
return 0;
}
// printf("%lld %lld\n",A,B);
for(int i=1;i<=n;i++){
read(l),read(r);
if(r-l+1>=A*B){
printf("%lld\n",A*B);
return 0;
}
l%=A*B,r%=A*B;
// printf("> %lld %lld\n",l,r);
if(l<=r){
sum[l]++,sum[r+1]--;
}else{
sum[0]++,sum[r+1]--;
sum[l]++,sum[A*B]--;
}
}
sum[A*B]+=0;
long long cnt=0,lst=0;
for(const auto &it:sum){
if(cnt)ans+=it.first-lst;
cnt+=it.second;
lst=it.first;
}
printf("%lld\n",ans);
}
Compilation message
strange_device.cpp: In function 'void read(T&)':
strange_device.cpp:3:21: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
3 | x=0; register char c=getchar(); register bool f=0;
| ^
strange_device.cpp:3:48: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
3 | x=0; register char c=getchar(); register bool f=0;
| ^
strange_device.cpp:5:2: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
5 | while(isdigit(c))x=x*10+c-'0',c=getchar(); if(f)x=-x;
| ^~~~~
strange_device.cpp:5:45: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
5 | while(isdigit(c))x=x*10+c-'0',c=getchar(); if(f)x=-x;
| ^~
strange_device.cpp: In instantiation of 'void read(T&) [with T = int]':
strange_device.cpp:16:8: required from here
strange_device.cpp:3:21: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
3 | x=0; register char c=getchar(); register bool f=0;
| ^
strange_device.cpp:3:48: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
3 | x=0; register char c=getchar(); register bool f=0;
| ^
strange_device.cpp: In instantiation of 'void read(T&) [with T = long long int]':
strange_device.cpp:16:16: required from here
strange_device.cpp:3:21: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
3 | x=0; register char c=getchar(); register bool f=0;
| ^
strange_device.cpp:3:48: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
3 | x=0; register char c=getchar(); register bool f=0;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
1236 KB |
Output is correct |
3 |
Correct |
4 ms |
1208 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
300 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 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 |
4 ms |
1252 KB |
Output is correct |
17 |
Correct |
64 ms |
10160 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
199 ms |
25348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
611 ms |
100008 KB |
Output is correct |
3 |
Correct |
544 ms |
99984 KB |
Output is correct |
4 |
Correct |
591 ms |
99948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
611 ms |
100008 KB |
Output is correct |
3 |
Correct |
544 ms |
99984 KB |
Output is correct |
4 |
Correct |
591 ms |
99948 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
642 ms |
99912 KB |
Output is correct |
7 |
Correct |
570 ms |
99912 KB |
Output is correct |
8 |
Correct |
496 ms |
99952 KB |
Output is correct |
9 |
Correct |
564 ms |
100132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
611 ms |
100008 KB |
Output is correct |
3 |
Correct |
544 ms |
99984 KB |
Output is correct |
4 |
Correct |
591 ms |
99948 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
40 ms |
10268 KB |
Output is correct |
7 |
Correct |
58 ms |
10256 KB |
Output is correct |
8 |
Correct |
49 ms |
10196 KB |
Output is correct |
9 |
Correct |
46 ms |
10188 KB |
Output is correct |
10 |
Correct |
39 ms |
10204 KB |
Output is correct |
11 |
Correct |
56 ms |
10244 KB |
Output is correct |
12 |
Correct |
69 ms |
10228 KB |
Output is correct |
13 |
Correct |
51 ms |
10148 KB |
Output is correct |
14 |
Correct |
39 ms |
10148 KB |
Output is correct |
15 |
Correct |
61 ms |
10204 KB |
Output is correct |
16 |
Correct |
52 ms |
10156 KB |
Output is correct |
17 |
Correct |
47 ms |
10188 KB |
Output is correct |
18 |
Correct |
506 ms |
99984 KB |
Output is correct |
19 |
Correct |
588 ms |
99296 KB |
Output is correct |
20 |
Correct |
583 ms |
98624 KB |
Output is correct |
21 |
Correct |
47 ms |
10168 KB |
Output is correct |
22 |
Correct |
43 ms |
10160 KB |
Output is correct |
23 |
Correct |
75 ms |
12800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
52 ms |
10220 KB |
Output is correct |
3 |
Correct |
72 ms |
10168 KB |
Output is correct |
4 |
Correct |
544 ms |
99672 KB |
Output is correct |
5 |
Correct |
50 ms |
10236 KB |
Output is correct |
6 |
Correct |
57 ms |
10176 KB |
Output is correct |
7 |
Correct |
50 ms |
10188 KB |
Output is correct |
8 |
Correct |
59 ms |
10236 KB |
Output is correct |
9 |
Correct |
48 ms |
10272 KB |
Output is correct |
10 |
Correct |
42 ms |
10188 KB |
Output is correct |
11 |
Correct |
45 ms |
10228 KB |
Output is correct |
12 |
Correct |
45 ms |
10260 KB |
Output is correct |
13 |
Correct |
58 ms |
10168 KB |
Output is correct |
14 |
Correct |
614 ms |
99928 KB |
Output is correct |
15 |
Correct |
49 ms |
10252 KB |
Output is correct |
16 |
Correct |
499 ms |
100032 KB |
Output is correct |
17 |
Correct |
506 ms |
100084 KB |
Output is correct |
18 |
Correct |
0 ms |
224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
1236 KB |
Output is correct |
3 |
Correct |
4 ms |
1208 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
300 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 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 |
4 ms |
1252 KB |
Output is correct |
17 |
Correct |
64 ms |
10160 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
300 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 |
199 ms |
25348 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
611 ms |
100008 KB |
Output is correct |
31 |
Correct |
544 ms |
99984 KB |
Output is correct |
32 |
Correct |
591 ms |
99948 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
642 ms |
99912 KB |
Output is correct |
35 |
Correct |
570 ms |
99912 KB |
Output is correct |
36 |
Correct |
496 ms |
99952 KB |
Output is correct |
37 |
Correct |
564 ms |
100132 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
40 ms |
10268 KB |
Output is correct |
40 |
Correct |
58 ms |
10256 KB |
Output is correct |
41 |
Correct |
49 ms |
10196 KB |
Output is correct |
42 |
Correct |
46 ms |
10188 KB |
Output is correct |
43 |
Correct |
39 ms |
10204 KB |
Output is correct |
44 |
Correct |
56 ms |
10244 KB |
Output is correct |
45 |
Correct |
69 ms |
10228 KB |
Output is correct |
46 |
Correct |
51 ms |
10148 KB |
Output is correct |
47 |
Correct |
39 ms |
10148 KB |
Output is correct |
48 |
Correct |
61 ms |
10204 KB |
Output is correct |
49 |
Correct |
52 ms |
10156 KB |
Output is correct |
50 |
Correct |
47 ms |
10188 KB |
Output is correct |
51 |
Correct |
506 ms |
99984 KB |
Output is correct |
52 |
Correct |
588 ms |
99296 KB |
Output is correct |
53 |
Correct |
583 ms |
98624 KB |
Output is correct |
54 |
Correct |
47 ms |
10168 KB |
Output is correct |
55 |
Correct |
43 ms |
10160 KB |
Output is correct |
56 |
Correct |
75 ms |
12800 KB |
Output is correct |
57 |
Correct |
1 ms |
212 KB |
Output is correct |
58 |
Correct |
52 ms |
10220 KB |
Output is correct |
59 |
Correct |
72 ms |
10168 KB |
Output is correct |
60 |
Correct |
544 ms |
99672 KB |
Output is correct |
61 |
Correct |
50 ms |
10236 KB |
Output is correct |
62 |
Correct |
57 ms |
10176 KB |
Output is correct |
63 |
Correct |
50 ms |
10188 KB |
Output is correct |
64 |
Correct |
59 ms |
10236 KB |
Output is correct |
65 |
Correct |
48 ms |
10272 KB |
Output is correct |
66 |
Correct |
42 ms |
10188 KB |
Output is correct |
67 |
Correct |
45 ms |
10228 KB |
Output is correct |
68 |
Correct |
45 ms |
10260 KB |
Output is correct |
69 |
Correct |
58 ms |
10168 KB |
Output is correct |
70 |
Correct |
614 ms |
99928 KB |
Output is correct |
71 |
Correct |
49 ms |
10252 KB |
Output is correct |
72 |
Correct |
499 ms |
100032 KB |
Output is correct |
73 |
Correct |
506 ms |
100084 KB |
Output is correct |
74 |
Correct |
0 ms |
224 KB |
Output is correct |
75 |
Correct |
1 ms |
212 KB |
Output is correct |
76 |
Correct |
1 ms |
300 KB |
Output is correct |
77 |
Correct |
1 ms |
300 KB |
Output is correct |
78 |
Correct |
1 ms |
212 KB |
Output is correct |
79 |
Correct |
5 ms |
1208 KB |
Output is correct |
80 |
Correct |
577 ms |
98436 KB |
Output is correct |
81 |
Correct |
584 ms |
94000 KB |
Output is correct |
82 |
Correct |
598 ms |
93680 KB |
Output is correct |
83 |
Correct |
588 ms |
85872 KB |
Output is correct |
84 |
Correct |
625 ms |
83300 KB |
Output is correct |
85 |
Correct |
548 ms |
82416 KB |
Output is correct |
86 |
Correct |
65 ms |
12804 KB |
Output is correct |
87 |
Correct |
1 ms |
212 KB |
Output is correct |