#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*b<=2e18)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=-1,l=0;
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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
1060 KB |
Output is correct |
3 |
Correct |
8 ms |
984 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
316 KB |
Output is correct |
7 |
Correct |
1 ms |
316 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 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 |
320 KB |
Output is correct |
15 |
Correct |
1 ms |
324 KB |
Output is correct |
16 |
Correct |
5 ms |
984 KB |
Output is correct |
17 |
Correct |
48 ms |
5652 KB |
Output is correct |
18 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
Incorrect |
1 ms |
320 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
307 ms |
19468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
459 ms |
25092 KB |
Output is correct |
3 |
Correct |
431 ms |
22672 KB |
Output is correct |
4 |
Correct |
435 ms |
28184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
459 ms |
25092 KB |
Output is correct |
3 |
Correct |
431 ms |
22672 KB |
Output is correct |
4 |
Correct |
435 ms |
28184 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
433 ms |
28188 KB |
Output is correct |
7 |
Correct |
439 ms |
28160 KB |
Output is correct |
8 |
Correct |
462 ms |
28176 KB |
Output is correct |
9 |
Correct |
472 ms |
28276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
459 ms |
25092 KB |
Output is correct |
3 |
Correct |
431 ms |
22672 KB |
Output is correct |
4 |
Correct |
435 ms |
28184 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
46 ms |
5676 KB |
Output is correct |
7 |
Correct |
45 ms |
5612 KB |
Output is correct |
8 |
Correct |
44 ms |
5716 KB |
Output is correct |
9 |
Correct |
44 ms |
5708 KB |
Output is correct |
10 |
Correct |
56 ms |
5692 KB |
Output is correct |
11 |
Correct |
46 ms |
5700 KB |
Output is correct |
12 |
Correct |
41 ms |
5700 KB |
Output is correct |
13 |
Correct |
44 ms |
5660 KB |
Output is correct |
14 |
Correct |
41 ms |
5612 KB |
Output is correct |
15 |
Correct |
57 ms |
5704 KB |
Output is correct |
16 |
Correct |
50 ms |
5668 KB |
Output is correct |
17 |
Correct |
42 ms |
5616 KB |
Output is correct |
18 |
Correct |
474 ms |
28244 KB |
Output is correct |
19 |
Correct |
450 ms |
28244 KB |
Output is correct |
20 |
Correct |
459 ms |
28184 KB |
Output is correct |
21 |
Correct |
46 ms |
5700 KB |
Output is correct |
22 |
Correct |
39 ms |
5732 KB |
Output is correct |
23 |
Correct |
144 ms |
17416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
46 ms |
5688 KB |
Output is correct |
3 |
Correct |
50 ms |
5616 KB |
Output is correct |
4 |
Correct |
496 ms |
27732 KB |
Output is correct |
5 |
Correct |
46 ms |
5760 KB |
Output is correct |
6 |
Correct |
43 ms |
5704 KB |
Output is correct |
7 |
Correct |
41 ms |
5692 KB |
Output is correct |
8 |
Correct |
43 ms |
5652 KB |
Output is correct |
9 |
Correct |
41 ms |
5628 KB |
Output is correct |
10 |
Correct |
41 ms |
5652 KB |
Output is correct |
11 |
Correct |
52 ms |
5708 KB |
Output is correct |
12 |
Correct |
36 ms |
5672 KB |
Output is correct |
13 |
Correct |
44 ms |
5628 KB |
Output is correct |
14 |
Correct |
460 ms |
27896 KB |
Output is correct |
15 |
Correct |
49 ms |
5672 KB |
Output is correct |
16 |
Correct |
391 ms |
28304 KB |
Output is correct |
17 |
Correct |
415 ms |
28220 KB |
Output is correct |
18 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
1060 KB |
Output is correct |
3 |
Correct |
8 ms |
984 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
316 KB |
Output is correct |
7 |
Correct |
1 ms |
316 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 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 |
320 KB |
Output is correct |
15 |
Correct |
1 ms |
324 KB |
Output is correct |
16 |
Correct |
5 ms |
984 KB |
Output is correct |
17 |
Correct |
48 ms |
5652 KB |
Output is correct |
18 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |