#include "bits/stdc++.h"
using namespace std;
#define ar array
#define int long long
/*
3 5 12
0 23
60 60
81 83
*/
const long long inf = 1e18 + 5;
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
int n, A, B; cin>>n>>A>>B;
int cyc = A / __gcd(A, B + 1);
if(cyc > inf / B) cyc = inf;
else cyc *= B;
vector<ar<int, 2>> tt;
for(int i=0;i<n;i++){
int l, r; cin>>l>>r;
if(r - l + 1 >= cyc){
cout<<cyc<<"\n";
return 0;
}
l %= cyc, r %= cyc;
if(l <= r){
tt.push_back({l, r});
} else {
tt.push_back({l, cyc - 1});
tt.push_back({0, r});
}
}
sort(tt.begin(), tt.end());
int res = 0, r = -1;
for(auto x : tt){
if(r < x[0]){
res += (x[1] - x[0] + 1);
} else if(r < x[1]){
res += (x[1] - r);
} r = max(r, x[1]);
}
cout<<res<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
6 ms |
1064 KB |
Output is correct |
3 |
Correct |
5 ms |
984 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
1 ms |
316 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 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 |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
1004 KB |
Output is correct |
17 |
Correct |
47 ms |
5688 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
360 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
358 ms |
41268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
468 ms |
26304 KB |
Output is correct |
3 |
Correct |
402 ms |
18644 KB |
Output is correct |
4 |
Correct |
390 ms |
18616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
468 ms |
26304 KB |
Output is correct |
3 |
Correct |
402 ms |
18644 KB |
Output is correct |
4 |
Correct |
390 ms |
18616 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
414 ms |
18568 KB |
Output is correct |
7 |
Correct |
418 ms |
18516 KB |
Output is correct |
8 |
Correct |
417 ms |
18544 KB |
Output is correct |
9 |
Correct |
451 ms |
18484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
468 ms |
26304 KB |
Output is correct |
3 |
Correct |
402 ms |
18644 KB |
Output is correct |
4 |
Correct |
390 ms |
18616 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
45 ms |
5672 KB |
Output is correct |
7 |
Correct |
47 ms |
5648 KB |
Output is correct |
8 |
Correct |
44 ms |
5620 KB |
Output is correct |
9 |
Correct |
45 ms |
5748 KB |
Output is correct |
10 |
Correct |
42 ms |
5640 KB |
Output is correct |
11 |
Correct |
42 ms |
5732 KB |
Output is correct |
12 |
Correct |
51 ms |
5656 KB |
Output is correct |
13 |
Correct |
44 ms |
5692 KB |
Output is correct |
14 |
Correct |
43 ms |
5644 KB |
Output is correct |
15 |
Correct |
49 ms |
5692 KB |
Output is correct |
16 |
Correct |
48 ms |
5700 KB |
Output is correct |
17 |
Correct |
46 ms |
5644 KB |
Output is correct |
18 |
Correct |
421 ms |
53180 KB |
Output is correct |
19 |
Correct |
412 ms |
53236 KB |
Output is correct |
20 |
Correct |
471 ms |
53424 KB |
Output is correct |
21 |
Correct |
48 ms |
5620 KB |
Output is correct |
22 |
Correct |
41 ms |
5624 KB |
Output is correct |
23 |
Correct |
141 ms |
18568 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
52 ms |
5708 KB |
Output is correct |
3 |
Correct |
49 ms |
5668 KB |
Output is correct |
4 |
Correct |
514 ms |
27024 KB |
Output is correct |
5 |
Correct |
47 ms |
5816 KB |
Output is correct |
6 |
Correct |
49 ms |
5596 KB |
Output is correct |
7 |
Correct |
50 ms |
5668 KB |
Output is correct |
8 |
Correct |
47 ms |
5652 KB |
Output is correct |
9 |
Correct |
47 ms |
5600 KB |
Output is correct |
10 |
Correct |
48 ms |
5700 KB |
Output is correct |
11 |
Correct |
47 ms |
5596 KB |
Output is correct |
12 |
Correct |
42 ms |
5688 KB |
Output is correct |
13 |
Correct |
47 ms |
5704 KB |
Output is correct |
14 |
Correct |
504 ms |
27068 KB |
Output is correct |
15 |
Correct |
46 ms |
5672 KB |
Output is correct |
16 |
Correct |
430 ms |
26968 KB |
Output is correct |
17 |
Correct |
438 ms |
27184 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
6 ms |
1064 KB |
Output is correct |
3 |
Correct |
5 ms |
984 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
1 ms |
316 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 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 |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
1004 KB |
Output is correct |
17 |
Correct |
47 ms |
5688 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 |
316 KB |
Output is correct |
21 |
Correct |
1 ms |
324 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
360 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
328 KB |
Output is correct |
28 |
Correct |
358 ms |
41268 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
468 ms |
26304 KB |
Output is correct |
31 |
Correct |
402 ms |
18644 KB |
Output is correct |
32 |
Correct |
390 ms |
18616 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
414 ms |
18568 KB |
Output is correct |
35 |
Correct |
418 ms |
18516 KB |
Output is correct |
36 |
Correct |
417 ms |
18544 KB |
Output is correct |
37 |
Correct |
451 ms |
18484 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
45 ms |
5672 KB |
Output is correct |
40 |
Correct |
47 ms |
5648 KB |
Output is correct |
41 |
Correct |
44 ms |
5620 KB |
Output is correct |
42 |
Correct |
45 ms |
5748 KB |
Output is correct |
43 |
Correct |
42 ms |
5640 KB |
Output is correct |
44 |
Correct |
42 ms |
5732 KB |
Output is correct |
45 |
Correct |
51 ms |
5656 KB |
Output is correct |
46 |
Correct |
44 ms |
5692 KB |
Output is correct |
47 |
Correct |
43 ms |
5644 KB |
Output is correct |
48 |
Correct |
49 ms |
5692 KB |
Output is correct |
49 |
Correct |
48 ms |
5700 KB |
Output is correct |
50 |
Correct |
46 ms |
5644 KB |
Output is correct |
51 |
Correct |
421 ms |
53180 KB |
Output is correct |
52 |
Correct |
412 ms |
53236 KB |
Output is correct |
53 |
Correct |
471 ms |
53424 KB |
Output is correct |
54 |
Correct |
48 ms |
5620 KB |
Output is correct |
55 |
Correct |
41 ms |
5624 KB |
Output is correct |
56 |
Correct |
141 ms |
18568 KB |
Output is correct |
57 |
Correct |
0 ms |
212 KB |
Output is correct |
58 |
Correct |
52 ms |
5708 KB |
Output is correct |
59 |
Correct |
49 ms |
5668 KB |
Output is correct |
60 |
Correct |
514 ms |
27024 KB |
Output is correct |
61 |
Correct |
47 ms |
5816 KB |
Output is correct |
62 |
Correct |
49 ms |
5596 KB |
Output is correct |
63 |
Correct |
50 ms |
5668 KB |
Output is correct |
64 |
Correct |
47 ms |
5652 KB |
Output is correct |
65 |
Correct |
47 ms |
5600 KB |
Output is correct |
66 |
Correct |
48 ms |
5700 KB |
Output is correct |
67 |
Correct |
47 ms |
5596 KB |
Output is correct |
68 |
Correct |
42 ms |
5688 KB |
Output is correct |
69 |
Correct |
47 ms |
5704 KB |
Output is correct |
70 |
Correct |
504 ms |
27068 KB |
Output is correct |
71 |
Correct |
46 ms |
5672 KB |
Output is correct |
72 |
Correct |
430 ms |
26968 KB |
Output is correct |
73 |
Correct |
438 ms |
27184 KB |
Output is correct |
74 |
Correct |
1 ms |
212 KB |
Output is correct |
75 |
Correct |
0 ms |
212 KB |
Output is correct |
76 |
Correct |
0 ms |
212 KB |
Output is correct |
77 |
Correct |
1 ms |
320 KB |
Output is correct |
78 |
Correct |
1 ms |
320 KB |
Output is correct |
79 |
Correct |
5 ms |
1000 KB |
Output is correct |
80 |
Correct |
528 ms |
53284 KB |
Output is correct |
81 |
Correct |
526 ms |
53332 KB |
Output is correct |
82 |
Correct |
478 ms |
53368 KB |
Output is correct |
83 |
Correct |
477 ms |
53228 KB |
Output is correct |
84 |
Correct |
480 ms |
53400 KB |
Output is correct |
85 |
Correct |
475 ms |
53272 KB |
Output is correct |
86 |
Correct |
144 ms |
18480 KB |
Output is correct |
87 |
Correct |
1 ms |
212 KB |
Output is correct |