#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+1;
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=max(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:27:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
27 | for(auto [l,r]:p){
| ^
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 |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
596 KB |
Output is correct |
3 |
Correct |
5 ms |
1036 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
304 KB |
Output is correct |
9 |
Correct |
1 ms |
300 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
304 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
5 ms |
968 KB |
Output is correct |
17 |
Correct |
48 ms |
5664 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
329 ms |
41220 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
478 ms |
16736 KB |
Output is correct |
3 |
Correct |
408 ms |
16780 KB |
Output is correct |
4 |
Correct |
392 ms |
16804 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
478 ms |
16736 KB |
Output is correct |
3 |
Correct |
408 ms |
16780 KB |
Output is correct |
4 |
Correct |
392 ms |
16804 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
421 ms |
16924 KB |
Output is correct |
7 |
Correct |
415 ms |
16884 KB |
Output is correct |
8 |
Correct |
406 ms |
16784 KB |
Output is correct |
9 |
Correct |
437 ms |
16740 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
478 ms |
16736 KB |
Output is correct |
3 |
Correct |
408 ms |
16780 KB |
Output is correct |
4 |
Correct |
392 ms |
16804 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
41 ms |
2424 KB |
Output is correct |
7 |
Correct |
43 ms |
2412 KB |
Output is correct |
8 |
Correct |
45 ms |
2388 KB |
Output is correct |
9 |
Correct |
41 ms |
2476 KB |
Output is correct |
10 |
Correct |
40 ms |
2376 KB |
Output is correct |
11 |
Correct |
43 ms |
2376 KB |
Output is correct |
12 |
Correct |
40 ms |
2480 KB |
Output is correct |
13 |
Correct |
43 ms |
2472 KB |
Output is correct |
14 |
Correct |
39 ms |
2488 KB |
Output is correct |
15 |
Correct |
44 ms |
2400 KB |
Output is correct |
16 |
Correct |
48 ms |
5592 KB |
Output is correct |
17 |
Correct |
46 ms |
5612 KB |
Output is correct |
18 |
Correct |
447 ms |
53240 KB |
Output is correct |
19 |
Correct |
435 ms |
53256 KB |
Output is correct |
20 |
Correct |
489 ms |
53320 KB |
Output is correct |
21 |
Correct |
46 ms |
5672 KB |
Output is correct |
22 |
Correct |
43 ms |
5620 KB |
Output is correct |
23 |
Correct |
135 ms |
18384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
45 ms |
2504 KB |
Output is correct |
3 |
Correct |
45 ms |
2536 KB |
Output is correct |
4 |
Correct |
486 ms |
16888 KB |
Output is correct |
5 |
Correct |
43 ms |
2496 KB |
Output is correct |
6 |
Correct |
43 ms |
2448 KB |
Output is correct |
7 |
Correct |
57 ms |
2500 KB |
Output is correct |
8 |
Correct |
43 ms |
2552 KB |
Output is correct |
9 |
Correct |
43 ms |
2472 KB |
Output is correct |
10 |
Correct |
46 ms |
2520 KB |
Output is correct |
11 |
Correct |
44 ms |
2508 KB |
Output is correct |
12 |
Correct |
38 ms |
2560 KB |
Output is correct |
13 |
Correct |
45 ms |
2520 KB |
Output is correct |
14 |
Correct |
443 ms |
16972 KB |
Output is correct |
15 |
Correct |
53 ms |
5788 KB |
Output is correct |
16 |
Correct |
451 ms |
53324 KB |
Output is correct |
17 |
Correct |
440 ms |
53244 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
596 KB |
Output is correct |
3 |
Correct |
5 ms |
1036 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
304 KB |
Output is correct |
9 |
Correct |
1 ms |
300 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
304 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
5 ms |
968 KB |
Output is correct |
17 |
Correct |
48 ms |
5664 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
320 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
329 ms |
41220 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
478 ms |
16736 KB |
Output is correct |
31 |
Correct |
408 ms |
16780 KB |
Output is correct |
32 |
Correct |
392 ms |
16804 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
421 ms |
16924 KB |
Output is correct |
35 |
Correct |
415 ms |
16884 KB |
Output is correct |
36 |
Correct |
406 ms |
16784 KB |
Output is correct |
37 |
Correct |
437 ms |
16740 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
41 ms |
2424 KB |
Output is correct |
40 |
Correct |
43 ms |
2412 KB |
Output is correct |
41 |
Correct |
45 ms |
2388 KB |
Output is correct |
42 |
Correct |
41 ms |
2476 KB |
Output is correct |
43 |
Correct |
40 ms |
2376 KB |
Output is correct |
44 |
Correct |
43 ms |
2376 KB |
Output is correct |
45 |
Correct |
40 ms |
2480 KB |
Output is correct |
46 |
Correct |
43 ms |
2472 KB |
Output is correct |
47 |
Correct |
39 ms |
2488 KB |
Output is correct |
48 |
Correct |
44 ms |
2400 KB |
Output is correct |
49 |
Correct |
48 ms |
5592 KB |
Output is correct |
50 |
Correct |
46 ms |
5612 KB |
Output is correct |
51 |
Correct |
447 ms |
53240 KB |
Output is correct |
52 |
Correct |
435 ms |
53256 KB |
Output is correct |
53 |
Correct |
489 ms |
53320 KB |
Output is correct |
54 |
Correct |
46 ms |
5672 KB |
Output is correct |
55 |
Correct |
43 ms |
5620 KB |
Output is correct |
56 |
Correct |
135 ms |
18384 KB |
Output is correct |
57 |
Correct |
1 ms |
212 KB |
Output is correct |
58 |
Correct |
45 ms |
2504 KB |
Output is correct |
59 |
Correct |
45 ms |
2536 KB |
Output is correct |
60 |
Correct |
486 ms |
16888 KB |
Output is correct |
61 |
Correct |
43 ms |
2496 KB |
Output is correct |
62 |
Correct |
43 ms |
2448 KB |
Output is correct |
63 |
Correct |
57 ms |
2500 KB |
Output is correct |
64 |
Correct |
43 ms |
2552 KB |
Output is correct |
65 |
Correct |
43 ms |
2472 KB |
Output is correct |
66 |
Correct |
46 ms |
2520 KB |
Output is correct |
67 |
Correct |
44 ms |
2508 KB |
Output is correct |
68 |
Correct |
38 ms |
2560 KB |
Output is correct |
69 |
Correct |
45 ms |
2520 KB |
Output is correct |
70 |
Correct |
443 ms |
16972 KB |
Output is correct |
71 |
Correct |
53 ms |
5788 KB |
Output is correct |
72 |
Correct |
451 ms |
53324 KB |
Output is correct |
73 |
Correct |
440 ms |
53244 KB |
Output is correct |
74 |
Correct |
0 ms |
212 KB |
Output is correct |
75 |
Correct |
1 ms |
304 KB |
Output is correct |
76 |
Correct |
0 ms |
212 KB |
Output is correct |
77 |
Correct |
1 ms |
212 KB |
Output is correct |
78 |
Correct |
1 ms |
332 KB |
Output is correct |
79 |
Correct |
5 ms |
980 KB |
Output is correct |
80 |
Correct |
529 ms |
53192 KB |
Output is correct |
81 |
Correct |
512 ms |
53232 KB |
Output is correct |
82 |
Correct |
479 ms |
53140 KB |
Output is correct |
83 |
Correct |
482 ms |
53232 KB |
Output is correct |
84 |
Correct |
480 ms |
52996 KB |
Output is correct |
85 |
Correct |
473 ms |
52900 KB |
Output is correct |
86 |
Correct |
145 ms |
18712 KB |
Output is correct |
87 |
Correct |
1 ms |
212 KB |
Output is correct |