#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define AquA cin.tie(0);ios_base::sync_with_stdio(0);
#define fs first
#define sc second
#define p_q priority_queue
using namespace std;
long long inf=2e18;
long long mul(long long x,long long y){
long long sum=inf;
if(sum/x>=y-2){
sum=min(sum,x*y);
}
return sum;
}
int main(){
AquA;
long long n,a,b;
cin >> n >> a >> b;
long long u=__gcd(a,(b+1));
a/=u;
long long sum=mul(a,b);
vector<pair<long long,long long> > x;
for(int i=0;i<n;i++){
long long l,r;
cin >> l >> r;
if(r/sum>l/sum+1){
cout << sum << "\n";
return 0;
}
if(r/sum==l/sum){
x.push_back({l%sum,r%sum});
}
else{
x.push_back({l%sum,sum-1});
x.push_back({0%sum,r%sum});
}
}
sort(x.begin(),x.end());
long long ans=0;
long long nw=0;
for(auto h:x){
nw=max(nw,h.fs);
if(h.sc>=nw){
ans+=(h.sc-nw+1);
}
nw=max(nw,h.sc+1);
}
cout << ans << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
724 KB |
Output is correct |
3 |
Correct |
4 ms |
600 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
312 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
320 KB |
Output is correct |
14 |
Correct |
1 ms |
320 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
984 KB |
Output is correct |
17 |
Correct |
45 ms |
5696 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 |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 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 |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
281 ms |
16768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
404 ms |
16936 KB |
Output is correct |
3 |
Correct |
375 ms |
16848 KB |
Output is correct |
4 |
Correct |
393 ms |
45100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
404 ms |
16936 KB |
Output is correct |
3 |
Correct |
375 ms |
16848 KB |
Output is correct |
4 |
Correct |
393 ms |
45100 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
410 ms |
44928 KB |
Output is correct |
7 |
Correct |
397 ms |
45108 KB |
Output is correct |
8 |
Correct |
405 ms |
45080 KB |
Output is correct |
9 |
Correct |
442 ms |
45172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
404 ms |
16936 KB |
Output is correct |
3 |
Correct |
375 ms |
16848 KB |
Output is correct |
4 |
Correct |
393 ms |
45100 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
41 ms |
5784 KB |
Output is correct |
7 |
Correct |
46 ms |
5780 KB |
Output is correct |
8 |
Correct |
42 ms |
5616 KB |
Output is correct |
9 |
Correct |
41 ms |
5704 KB |
Output is correct |
10 |
Correct |
41 ms |
5784 KB |
Output is correct |
11 |
Correct |
41 ms |
5724 KB |
Output is correct |
12 |
Correct |
42 ms |
5688 KB |
Output is correct |
13 |
Correct |
44 ms |
5784 KB |
Output is correct |
14 |
Correct |
39 ms |
5624 KB |
Output is correct |
15 |
Correct |
47 ms |
5700 KB |
Output is correct |
16 |
Correct |
42 ms |
5688 KB |
Output is correct |
17 |
Correct |
41 ms |
5796 KB |
Output is correct |
18 |
Correct |
413 ms |
44972 KB |
Output is correct |
19 |
Correct |
418 ms |
45008 KB |
Output is correct |
20 |
Correct |
441 ms |
45020 KB |
Output is correct |
21 |
Correct |
44 ms |
5720 KB |
Output is correct |
22 |
Correct |
39 ms |
5704 KB |
Output is correct |
23 |
Correct |
124 ms |
18428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
41 ms |
2392 KB |
Output is correct |
3 |
Correct |
39 ms |
2420 KB |
Output is correct |
4 |
Correct |
426 ms |
16744 KB |
Output is correct |
5 |
Correct |
38 ms |
2640 KB |
Output is correct |
6 |
Correct |
39 ms |
2376 KB |
Output is correct |
7 |
Correct |
38 ms |
2472 KB |
Output is correct |
8 |
Correct |
39 ms |
2512 KB |
Output is correct |
9 |
Correct |
40 ms |
2516 KB |
Output is correct |
10 |
Correct |
41 ms |
2512 KB |
Output is correct |
11 |
Correct |
41 ms |
2456 KB |
Output is correct |
12 |
Correct |
35 ms |
2512 KB |
Output is correct |
13 |
Correct |
38 ms |
2484 KB |
Output is correct |
14 |
Correct |
412 ms |
16796 KB |
Output is correct |
15 |
Correct |
39 ms |
2452 KB |
Output is correct |
16 |
Correct |
399 ms |
53172 KB |
Output is correct |
17 |
Correct |
409 ms |
53164 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 |
5 ms |
724 KB |
Output is correct |
3 |
Correct |
4 ms |
600 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
312 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
320 KB |
Output is correct |
14 |
Correct |
1 ms |
320 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
984 KB |
Output is correct |
17 |
Correct |
45 ms |
5696 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 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 |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
281 ms |
16768 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
404 ms |
16936 KB |
Output is correct |
31 |
Correct |
375 ms |
16848 KB |
Output is correct |
32 |
Correct |
393 ms |
45100 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
410 ms |
44928 KB |
Output is correct |
35 |
Correct |
397 ms |
45108 KB |
Output is correct |
36 |
Correct |
405 ms |
45080 KB |
Output is correct |
37 |
Correct |
442 ms |
45172 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
41 ms |
5784 KB |
Output is correct |
40 |
Correct |
46 ms |
5780 KB |
Output is correct |
41 |
Correct |
42 ms |
5616 KB |
Output is correct |
42 |
Correct |
41 ms |
5704 KB |
Output is correct |
43 |
Correct |
41 ms |
5784 KB |
Output is correct |
44 |
Correct |
41 ms |
5724 KB |
Output is correct |
45 |
Correct |
42 ms |
5688 KB |
Output is correct |
46 |
Correct |
44 ms |
5784 KB |
Output is correct |
47 |
Correct |
39 ms |
5624 KB |
Output is correct |
48 |
Correct |
47 ms |
5700 KB |
Output is correct |
49 |
Correct |
42 ms |
5688 KB |
Output is correct |
50 |
Correct |
41 ms |
5796 KB |
Output is correct |
51 |
Correct |
413 ms |
44972 KB |
Output is correct |
52 |
Correct |
418 ms |
45008 KB |
Output is correct |
53 |
Correct |
441 ms |
45020 KB |
Output is correct |
54 |
Correct |
44 ms |
5720 KB |
Output is correct |
55 |
Correct |
39 ms |
5704 KB |
Output is correct |
56 |
Correct |
124 ms |
18428 KB |
Output is correct |
57 |
Correct |
0 ms |
212 KB |
Output is correct |
58 |
Correct |
41 ms |
2392 KB |
Output is correct |
59 |
Correct |
39 ms |
2420 KB |
Output is correct |
60 |
Correct |
426 ms |
16744 KB |
Output is correct |
61 |
Correct |
38 ms |
2640 KB |
Output is correct |
62 |
Correct |
39 ms |
2376 KB |
Output is correct |
63 |
Correct |
38 ms |
2472 KB |
Output is correct |
64 |
Correct |
39 ms |
2512 KB |
Output is correct |
65 |
Correct |
40 ms |
2516 KB |
Output is correct |
66 |
Correct |
41 ms |
2512 KB |
Output is correct |
67 |
Correct |
41 ms |
2456 KB |
Output is correct |
68 |
Correct |
35 ms |
2512 KB |
Output is correct |
69 |
Correct |
38 ms |
2484 KB |
Output is correct |
70 |
Correct |
412 ms |
16796 KB |
Output is correct |
71 |
Correct |
39 ms |
2452 KB |
Output is correct |
72 |
Correct |
399 ms |
53172 KB |
Output is correct |
73 |
Correct |
409 ms |
53164 KB |
Output is correct |
74 |
Correct |
1 ms |
212 KB |
Output is correct |
75 |
Correct |
1 ms |
212 KB |
Output is correct |
76 |
Correct |
1 ms |
212 KB |
Output is correct |
77 |
Correct |
1 ms |
320 KB |
Output is correct |
78 |
Correct |
1 ms |
212 KB |
Output is correct |
79 |
Correct |
5 ms |
984 KB |
Output is correct |
80 |
Correct |
487 ms |
53272 KB |
Output is correct |
81 |
Correct |
495 ms |
53288 KB |
Output is correct |
82 |
Correct |
440 ms |
53088 KB |
Output is correct |
83 |
Correct |
450 ms |
53072 KB |
Output is correct |
84 |
Correct |
578 ms |
53060 KB |
Output is correct |
85 |
Correct |
453 ms |
52980 KB |
Output is correct |
86 |
Correct |
132 ms |
18424 KB |
Output is correct |
87 |
Correct |
1 ms |
212 KB |
Output is correct |