#include <iostream>
#include <bits/stdc++.h>
using namespace std;
vector<pair<long long,long long>> seg;
int main(){
long long n,a,b;
cin>>n>>a>>b;
a/=__gcd(a,b+1);
long long mx = 1e18;
if(mx/a<=b){
mx = 1e18;
}else{
mx = a*b;
}
for(int i=0;i<n;i++){
long long l,r;
cin>>l>>r;
if(r-l+1>=mx){
cout<<mx<<endl;
return 0;
}
l%=mx;
r%=mx;
if(l<=r){
seg.push_back(make_pair(l,r));
}else{
seg.push_back(make_pair(l,mx-1));
seg.push_back(make_pair(0,r));
}
}
sort(seg.begin(),seg.end());
long long ans = 0;
long long l = seg[0].first;
long long r = seg[0].second;
for(auto x:seg){
if(r<x.first){
ans+=r-l+1;
l=x.first;
r=x.second;
}else{
r= max(r,x.second);
}
}
ans+=(r-l+1);
cout<<ans<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
28 ms |
1020 KB |
Output is correct |
3 |
Correct |
26 ms |
1016 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
256 KB |
Output is correct |
7 |
Correct |
5 ms |
256 KB |
Output is correct |
8 |
Correct |
5 ms |
256 KB |
Output is correct |
9 |
Correct |
5 ms |
256 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
5 ms |
256 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
256 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
29 ms |
1016 KB |
Output is correct |
17 |
Correct |
252 ms |
5692 KB |
Output is correct |
18 |
Correct |
5 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
4 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
8 ms |
376 KB |
Output is correct |
3 |
Correct |
7 ms |
376 KB |
Output is correct |
4 |
Correct |
7 ms |
376 KB |
Output is correct |
5 |
Correct |
1560 ms |
41404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
2185 ms |
53428 KB |
Output is correct |
3 |
Correct |
2185 ms |
53208 KB |
Output is correct |
4 |
Correct |
2175 ms |
31980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
2185 ms |
53428 KB |
Output is correct |
3 |
Correct |
2185 ms |
53208 KB |
Output is correct |
4 |
Correct |
2175 ms |
31980 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
2167 ms |
32264 KB |
Output is correct |
7 |
Correct |
2180 ms |
32728 KB |
Output is correct |
8 |
Correct |
2167 ms |
31956 KB |
Output is correct |
9 |
Correct |
2249 ms |
32572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
2185 ms |
53428 KB |
Output is correct |
3 |
Correct |
2185 ms |
53208 KB |
Output is correct |
4 |
Correct |
2175 ms |
31980 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
223 ms |
5780 KB |
Output is correct |
7 |
Correct |
229 ms |
5832 KB |
Output is correct |
8 |
Correct |
222 ms |
5868 KB |
Output is correct |
9 |
Correct |
225 ms |
5732 KB |
Output is correct |
10 |
Correct |
225 ms |
5732 KB |
Output is correct |
11 |
Correct |
223 ms |
5732 KB |
Output is correct |
12 |
Correct |
230 ms |
5876 KB |
Output is correct |
13 |
Correct |
223 ms |
5732 KB |
Output is correct |
14 |
Correct |
222 ms |
5732 KB |
Output is correct |
15 |
Correct |
226 ms |
5860 KB |
Output is correct |
16 |
Correct |
225 ms |
5736 KB |
Output is correct |
17 |
Correct |
225 ms |
5816 KB |
Output is correct |
18 |
Correct |
2193 ms |
32240 KB |
Output is correct |
19 |
Correct |
2170 ms |
32576 KB |
Output is correct |
20 |
Correct |
2227 ms |
32412 KB |
Output is correct |
21 |
Correct |
227 ms |
5840 KB |
Output is correct |
22 |
Correct |
222 ms |
5732 KB |
Output is correct |
23 |
Correct |
734 ms |
18536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
227 ms |
5760 KB |
Output is correct |
3 |
Correct |
225 ms |
5736 KB |
Output is correct |
4 |
Correct |
2250 ms |
32316 KB |
Output is correct |
5 |
Correct |
245 ms |
5732 KB |
Output is correct |
6 |
Correct |
232 ms |
5732 KB |
Output is correct |
7 |
Correct |
227 ms |
5732 KB |
Output is correct |
8 |
Correct |
228 ms |
5732 KB |
Output is correct |
9 |
Correct |
227 ms |
5884 KB |
Output is correct |
10 |
Correct |
247 ms |
5728 KB |
Output is correct |
11 |
Correct |
230 ms |
5804 KB |
Output is correct |
12 |
Correct |
217 ms |
5732 KB |
Output is correct |
13 |
Correct |
225 ms |
5732 KB |
Output is correct |
14 |
Correct |
2238 ms |
32228 KB |
Output is correct |
15 |
Correct |
229 ms |
5732 KB |
Output is correct |
16 |
Correct |
2178 ms |
32380 KB |
Output is correct |
17 |
Correct |
2191 ms |
32216 KB |
Output is correct |
18 |
Correct |
5 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
28 ms |
1020 KB |
Output is correct |
3 |
Correct |
26 ms |
1016 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
256 KB |
Output is correct |
7 |
Correct |
5 ms |
256 KB |
Output is correct |
8 |
Correct |
5 ms |
256 KB |
Output is correct |
9 |
Correct |
5 ms |
256 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
5 ms |
256 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
256 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
29 ms |
1016 KB |
Output is correct |
17 |
Correct |
252 ms |
5692 KB |
Output is correct |
18 |
Correct |
5 ms |
256 KB |
Output is correct |
19 |
Correct |
5 ms |
256 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
256 KB |
Output is correct |
22 |
Correct |
4 ms |
256 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
256 KB |
Output is correct |
25 |
Correct |
8 ms |
376 KB |
Output is correct |
26 |
Correct |
7 ms |
376 KB |
Output is correct |
27 |
Correct |
7 ms |
376 KB |
Output is correct |
28 |
Correct |
1560 ms |
41404 KB |
Output is correct |
29 |
Correct |
5 ms |
376 KB |
Output is correct |
30 |
Correct |
2185 ms |
53428 KB |
Output is correct |
31 |
Correct |
2185 ms |
53208 KB |
Output is correct |
32 |
Correct |
2175 ms |
31980 KB |
Output is correct |
33 |
Correct |
5 ms |
256 KB |
Output is correct |
34 |
Correct |
2167 ms |
32264 KB |
Output is correct |
35 |
Correct |
2180 ms |
32728 KB |
Output is correct |
36 |
Correct |
2167 ms |
31956 KB |
Output is correct |
37 |
Correct |
2249 ms |
32572 KB |
Output is correct |
38 |
Correct |
5 ms |
376 KB |
Output is correct |
39 |
Correct |
223 ms |
5780 KB |
Output is correct |
40 |
Correct |
229 ms |
5832 KB |
Output is correct |
41 |
Correct |
222 ms |
5868 KB |
Output is correct |
42 |
Correct |
225 ms |
5732 KB |
Output is correct |
43 |
Correct |
225 ms |
5732 KB |
Output is correct |
44 |
Correct |
223 ms |
5732 KB |
Output is correct |
45 |
Correct |
230 ms |
5876 KB |
Output is correct |
46 |
Correct |
223 ms |
5732 KB |
Output is correct |
47 |
Correct |
222 ms |
5732 KB |
Output is correct |
48 |
Correct |
226 ms |
5860 KB |
Output is correct |
49 |
Correct |
225 ms |
5736 KB |
Output is correct |
50 |
Correct |
225 ms |
5816 KB |
Output is correct |
51 |
Correct |
2193 ms |
32240 KB |
Output is correct |
52 |
Correct |
2170 ms |
32576 KB |
Output is correct |
53 |
Correct |
2227 ms |
32412 KB |
Output is correct |
54 |
Correct |
227 ms |
5840 KB |
Output is correct |
55 |
Correct |
222 ms |
5732 KB |
Output is correct |
56 |
Correct |
734 ms |
18536 KB |
Output is correct |
57 |
Correct |
5 ms |
256 KB |
Output is correct |
58 |
Correct |
227 ms |
5760 KB |
Output is correct |
59 |
Correct |
225 ms |
5736 KB |
Output is correct |
60 |
Correct |
2250 ms |
32316 KB |
Output is correct |
61 |
Correct |
245 ms |
5732 KB |
Output is correct |
62 |
Correct |
232 ms |
5732 KB |
Output is correct |
63 |
Correct |
227 ms |
5732 KB |
Output is correct |
64 |
Correct |
228 ms |
5732 KB |
Output is correct |
65 |
Correct |
227 ms |
5884 KB |
Output is correct |
66 |
Correct |
247 ms |
5728 KB |
Output is correct |
67 |
Correct |
230 ms |
5804 KB |
Output is correct |
68 |
Correct |
217 ms |
5732 KB |
Output is correct |
69 |
Correct |
225 ms |
5732 KB |
Output is correct |
70 |
Correct |
2238 ms |
32228 KB |
Output is correct |
71 |
Correct |
229 ms |
5732 KB |
Output is correct |
72 |
Correct |
2178 ms |
32380 KB |
Output is correct |
73 |
Correct |
2191 ms |
32216 KB |
Output is correct |
74 |
Correct |
5 ms |
256 KB |
Output is correct |
75 |
Correct |
5 ms |
256 KB |
Output is correct |
76 |
Correct |
5 ms |
256 KB |
Output is correct |
77 |
Correct |
5 ms |
256 KB |
Output is correct |
78 |
Correct |
5 ms |
256 KB |
Output is correct |
79 |
Correct |
26 ms |
1016 KB |
Output is correct |
80 |
Correct |
2260 ms |
31888 KB |
Output is correct |
81 |
Correct |
2250 ms |
31976 KB |
Output is correct |
82 |
Correct |
2208 ms |
32064 KB |
Output is correct |
83 |
Correct |
2221 ms |
32036 KB |
Output is correct |
84 |
Correct |
2244 ms |
32400 KB |
Output is correct |
85 |
Correct |
2247 ms |
32444 KB |
Output is correct |
86 |
Correct |
735 ms |
18552 KB |
Output is correct |
87 |
Correct |
5 ms |
256 KB |
Output is correct |