#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(1e18/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);
| ~~~~~^~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
5 ms |
952 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
300 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 |
300 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
296 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
304 KB |
Output is correct |
2 |
Correct |
432 ms |
17556 KB |
Output is correct |
3 |
Correct |
398 ms |
17556 KB |
Output is correct |
4 |
Correct |
402 ms |
17684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
304 KB |
Output is correct |
2 |
Correct |
432 ms |
17556 KB |
Output is correct |
3 |
Correct |
398 ms |
17556 KB |
Output is correct |
4 |
Correct |
402 ms |
17684 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
405 ms |
17576 KB |
Output is correct |
7 |
Correct |
410 ms |
17568 KB |
Output is correct |
8 |
Correct |
400 ms |
17412 KB |
Output is correct |
9 |
Correct |
440 ms |
17364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
304 KB |
Output is correct |
2 |
Correct |
432 ms |
17556 KB |
Output is correct |
3 |
Correct |
398 ms |
17556 KB |
Output is correct |
4 |
Correct |
402 ms |
17684 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
45 ms |
5648 KB |
Output is correct |
7 |
Correct |
47 ms |
5616 KB |
Output is correct |
8 |
Correct |
45 ms |
5668 KB |
Output is correct |
9 |
Correct |
43 ms |
5640 KB |
Output is correct |
10 |
Correct |
42 ms |
5688 KB |
Output is correct |
11 |
Correct |
45 ms |
5604 KB |
Output is correct |
12 |
Correct |
42 ms |
5660 KB |
Output is correct |
13 |
Correct |
46 ms |
5680 KB |
Output is correct |
14 |
Correct |
42 ms |
5640 KB |
Output is correct |
15 |
Incorrect |
46 ms |
5756 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
300 KB |
Output is correct |
2 |
Correct |
46 ms |
5632 KB |
Output is correct |
3 |
Correct |
46 ms |
5692 KB |
Output is correct |
4 |
Correct |
467 ms |
17440 KB |
Output is correct |
5 |
Correct |
48 ms |
5076 KB |
Output is correct |
6 |
Correct |
45 ms |
5140 KB |
Output is correct |
7 |
Correct |
44 ms |
5020 KB |
Output is correct |
8 |
Correct |
45 ms |
5112 KB |
Output is correct |
9 |
Correct |
48 ms |
5068 KB |
Output is correct |
10 |
Correct |
46 ms |
4816 KB |
Output is correct |
11 |
Correct |
43 ms |
4772 KB |
Output is correct |
12 |
Correct |
41 ms |
4584 KB |
Output is correct |
13 |
Correct |
44 ms |
4416 KB |
Output is correct |
14 |
Incorrect |
432 ms |
17236 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
5 ms |
952 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |