#include<bits/stdc++.h>
using namespace std;
#define N 1000005
long long a,b,g,rb,l,r,ll,rr,flag,ans;
vector<pair<long long,long long>> p;
int main(){
int n,i;
scanf("%d %lld %lld",&n,&a,&b);
g=__gcd(a,b+1);
r=a/g;
if(1000000000000000000ll/r>=b)rb=r*b;
else rb=1e18+5;
for(i=1;i<=n;i++){
scanf("%lld %lld",&l,&r);
if(r-l+1>=rb)flag=true;
l%=rb;
r%=rb;
if(l<=r)p.push_back({l,r});
else p.push_back({l,rb-1}),p.push_back({0,r});
}
if(flag){printf("%lld",rb);return 0;}
sort(p.begin(),p.end());
ll=-1;
rr=-2;
for(auto [l,r]:p){
if(l<=rr)rr=r;
else{
ans+=rr-ll+1;
ll=l,rr=r;
}
}
ans+=rr-ll+1;
printf("%lld",ans);
return 0;
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
10 | scanf("%d %lld %lld",&n,&a,&b);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:16:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
16 | scanf("%lld %lld",&l,&r);
| ~~~~~^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
5 ms |
724 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
300 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
444 ms |
17276 KB |
Output is correct |
3 |
Correct |
432 ms |
17352 KB |
Output is correct |
4 |
Correct |
420 ms |
17368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
444 ms |
17276 KB |
Output is correct |
3 |
Correct |
432 ms |
17352 KB |
Output is correct |
4 |
Correct |
420 ms |
17368 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
431 ms |
17288 KB |
Output is correct |
7 |
Correct |
431 ms |
17240 KB |
Output is correct |
8 |
Correct |
422 ms |
17316 KB |
Output is correct |
9 |
Correct |
455 ms |
17388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
444 ms |
17276 KB |
Output is correct |
3 |
Correct |
432 ms |
17352 KB |
Output is correct |
4 |
Correct |
420 ms |
17368 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
43 ms |
2496 KB |
Output is correct |
7 |
Correct |
59 ms |
2496 KB |
Output is correct |
8 |
Correct |
45 ms |
2560 KB |
Output is correct |
9 |
Correct |
40 ms |
2564 KB |
Output is correct |
10 |
Correct |
41 ms |
2480 KB |
Output is correct |
11 |
Correct |
43 ms |
2536 KB |
Output is correct |
12 |
Correct |
44 ms |
2572 KB |
Output is correct |
13 |
Correct |
44 ms |
2564 KB |
Output is correct |
14 |
Correct |
40 ms |
2516 KB |
Output is correct |
15 |
Incorrect |
47 ms |
2512 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
45 ms |
2552 KB |
Output is correct |
3 |
Correct |
50 ms |
2588 KB |
Output is correct |
4 |
Correct |
491 ms |
17504 KB |
Output is correct |
5 |
Correct |
46 ms |
2496 KB |
Output is correct |
6 |
Correct |
46 ms |
2592 KB |
Output is correct |
7 |
Correct |
44 ms |
2568 KB |
Output is correct |
8 |
Correct |
45 ms |
2632 KB |
Output is correct |
9 |
Correct |
42 ms |
2604 KB |
Output is correct |
10 |
Correct |
46 ms |
2552 KB |
Output is correct |
11 |
Correct |
50 ms |
2672 KB |
Output is correct |
12 |
Correct |
40 ms |
2744 KB |
Output is correct |
13 |
Correct |
45 ms |
2620 KB |
Output is correct |
14 |
Incorrect |
462 ms |
17312 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
5 ms |
724 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |