#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
vector <pair <ll, ll>> vec;
int main(){
ios_base::sync_with_stdio(false);
cout.precision(10);
cout<<fixed;
int n;
cin >> n;
ll a, b;
cin >> a >> b;
a /= __gcd(a, b+1);
if(a <= 2000000000000000000LL/b) a *= b;
while(n--){
ll l, r;
cin >> l >> r;
if(r-l+1 >= a){
cout << a << "\n";
return 0;
}
l %= a;
r %= a;
if(l > r){
vec.push_back({0, 1});
vec.push_back({r+1, -1});
vec.push_back({l, 1});
vec.push_back({a, -1});
}
else{
vec.push_back({l, 1});
vec.push_back({r+1, -1});
}
}
sort(vec.begin(), vec.end());
n = vec.size();
ll res = 0;
ll tren = 0;
for(int i=0; i<n; i++){
ll val = vec[i].first;
if(i > 0) val -= vec[i-1].first;
if(tren) res += val;
tren += vec[i].second;
}
cout << res;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
7 ms |
1276 KB |
Output is correct |
3 |
Correct |
8 ms |
1200 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
312 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
292 KB |
Output is correct |
15 |
Correct |
1 ms |
304 KB |
Output is correct |
16 |
Correct |
7 ms |
1320 KB |
Output is correct |
17 |
Correct |
78 ms |
7164 KB |
Output is correct |
18 |
Correct |
1 ms |
316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
312 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
487 ms |
39920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
652 ms |
43308 KB |
Output is correct |
3 |
Correct |
700 ms |
43300 KB |
Output is correct |
4 |
Correct |
687 ms |
43384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
652 ms |
43308 KB |
Output is correct |
3 |
Correct |
700 ms |
43300 KB |
Output is correct |
4 |
Correct |
687 ms |
43384 KB |
Output is correct |
5 |
Correct |
0 ms |
316 KB |
Output is correct |
6 |
Correct |
640 ms |
43356 KB |
Output is correct |
7 |
Correct |
636 ms |
43412 KB |
Output is correct |
8 |
Correct |
613 ms |
43236 KB |
Output is correct |
9 |
Correct |
778 ms |
43244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
652 ms |
43308 KB |
Output is correct |
3 |
Correct |
700 ms |
43300 KB |
Output is correct |
4 |
Correct |
687 ms |
43384 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
60 ms |
7172 KB |
Output is correct |
7 |
Correct |
67 ms |
7260 KB |
Output is correct |
8 |
Correct |
60 ms |
7220 KB |
Output is correct |
9 |
Correct |
64 ms |
7196 KB |
Output is correct |
10 |
Correct |
59 ms |
7236 KB |
Output is correct |
11 |
Correct |
61 ms |
7260 KB |
Output is correct |
12 |
Correct |
57 ms |
7168 KB |
Output is correct |
13 |
Correct |
66 ms |
7268 KB |
Output is correct |
14 |
Correct |
60 ms |
7224 KB |
Output is correct |
15 |
Correct |
71 ms |
7248 KB |
Output is correct |
16 |
Correct |
68 ms |
7172 KB |
Output is correct |
17 |
Correct |
60 ms |
7236 KB |
Output is correct |
18 |
Correct |
647 ms |
51516 KB |
Output is correct |
19 |
Correct |
601 ms |
51668 KB |
Output is correct |
20 |
Correct |
752 ms |
51768 KB |
Output is correct |
21 |
Correct |
71 ms |
7220 KB |
Output is correct |
22 |
Correct |
58 ms |
7216 KB |
Output is correct |
23 |
Correct |
177 ms |
26692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
67 ms |
7180 KB |
Output is correct |
3 |
Correct |
71 ms |
7244 KB |
Output is correct |
4 |
Correct |
807 ms |
44832 KB |
Output is correct |
5 |
Correct |
68 ms |
7228 KB |
Output is correct |
6 |
Correct |
83 ms |
7304 KB |
Output is correct |
7 |
Correct |
66 ms |
7284 KB |
Output is correct |
8 |
Correct |
67 ms |
7216 KB |
Output is correct |
9 |
Correct |
69 ms |
7208 KB |
Output is correct |
10 |
Correct |
72 ms |
7208 KB |
Output is correct |
11 |
Correct |
67 ms |
7244 KB |
Output is correct |
12 |
Correct |
60 ms |
7220 KB |
Output is correct |
13 |
Correct |
69 ms |
7232 KB |
Output is correct |
14 |
Correct |
730 ms |
43252 KB |
Output is correct |
15 |
Correct |
72 ms |
7228 KB |
Output is correct |
16 |
Correct |
606 ms |
68788 KB |
Output is correct |
17 |
Correct |
626 ms |
68844 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
7 ms |
1276 KB |
Output is correct |
3 |
Correct |
8 ms |
1200 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
312 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
292 KB |
Output is correct |
15 |
Correct |
1 ms |
304 KB |
Output is correct |
16 |
Correct |
7 ms |
1320 KB |
Output is correct |
17 |
Correct |
78 ms |
7164 KB |
Output is correct |
18 |
Correct |
1 ms |
316 KB |
Output is correct |
19 |
Correct |
0 ms |
312 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
0 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
328 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
487 ms |
39920 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
652 ms |
43308 KB |
Output is correct |
31 |
Correct |
700 ms |
43300 KB |
Output is correct |
32 |
Correct |
687 ms |
43384 KB |
Output is correct |
33 |
Correct |
0 ms |
316 KB |
Output is correct |
34 |
Correct |
640 ms |
43356 KB |
Output is correct |
35 |
Correct |
636 ms |
43412 KB |
Output is correct |
36 |
Correct |
613 ms |
43236 KB |
Output is correct |
37 |
Correct |
778 ms |
43244 KB |
Output is correct |
38 |
Correct |
1 ms |
204 KB |
Output is correct |
39 |
Correct |
60 ms |
7172 KB |
Output is correct |
40 |
Correct |
67 ms |
7260 KB |
Output is correct |
41 |
Correct |
60 ms |
7220 KB |
Output is correct |
42 |
Correct |
64 ms |
7196 KB |
Output is correct |
43 |
Correct |
59 ms |
7236 KB |
Output is correct |
44 |
Correct |
61 ms |
7260 KB |
Output is correct |
45 |
Correct |
57 ms |
7168 KB |
Output is correct |
46 |
Correct |
66 ms |
7268 KB |
Output is correct |
47 |
Correct |
60 ms |
7224 KB |
Output is correct |
48 |
Correct |
71 ms |
7248 KB |
Output is correct |
49 |
Correct |
68 ms |
7172 KB |
Output is correct |
50 |
Correct |
60 ms |
7236 KB |
Output is correct |
51 |
Correct |
647 ms |
51516 KB |
Output is correct |
52 |
Correct |
601 ms |
51668 KB |
Output is correct |
53 |
Correct |
752 ms |
51768 KB |
Output is correct |
54 |
Correct |
71 ms |
7220 KB |
Output is correct |
55 |
Correct |
58 ms |
7216 KB |
Output is correct |
56 |
Correct |
177 ms |
26692 KB |
Output is correct |
57 |
Correct |
0 ms |
204 KB |
Output is correct |
58 |
Correct |
67 ms |
7180 KB |
Output is correct |
59 |
Correct |
71 ms |
7244 KB |
Output is correct |
60 |
Correct |
807 ms |
44832 KB |
Output is correct |
61 |
Correct |
68 ms |
7228 KB |
Output is correct |
62 |
Correct |
83 ms |
7304 KB |
Output is correct |
63 |
Correct |
66 ms |
7284 KB |
Output is correct |
64 |
Correct |
67 ms |
7216 KB |
Output is correct |
65 |
Correct |
69 ms |
7208 KB |
Output is correct |
66 |
Correct |
72 ms |
7208 KB |
Output is correct |
67 |
Correct |
67 ms |
7244 KB |
Output is correct |
68 |
Correct |
60 ms |
7220 KB |
Output is correct |
69 |
Correct |
69 ms |
7232 KB |
Output is correct |
70 |
Correct |
730 ms |
43252 KB |
Output is correct |
71 |
Correct |
72 ms |
7228 KB |
Output is correct |
72 |
Correct |
606 ms |
68788 KB |
Output is correct |
73 |
Correct |
626 ms |
68844 KB |
Output is correct |
74 |
Correct |
1 ms |
204 KB |
Output is correct |
75 |
Correct |
0 ms |
204 KB |
Output is correct |
76 |
Correct |
1 ms |
204 KB |
Output is correct |
77 |
Correct |
0 ms |
204 KB |
Output is correct |
78 |
Correct |
1 ms |
204 KB |
Output is correct |
79 |
Correct |
6 ms |
1228 KB |
Output is correct |
80 |
Correct |
820 ms |
52292 KB |
Output is correct |
81 |
Correct |
785 ms |
68768 KB |
Output is correct |
82 |
Correct |
765 ms |
68844 KB |
Output is correct |
83 |
Correct |
733 ms |
68832 KB |
Output is correct |
84 |
Correct |
746 ms |
68840 KB |
Output is correct |
85 |
Correct |
711 ms |
68760 KB |
Output is correct |
86 |
Correct |
207 ms |
26612 KB |
Output is correct |
87 |
Correct |
1 ms |
204 KB |
Output is correct |