#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
ll a, b;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> a >> b;
ll k = a / __gcd(a, b + 1);
ll cycle = 0;
if (b > 2e18 / k)
cycle = 2e18;
else
cycle = b * k;
vector<pair<ll, int>> e;
auto addSegment = [&](ll l, ll r){
e.push_back({l, 1});
e.push_back({r + 1, -1});
};
for(int i = 1; i <= n; i++){
ll l, r;
cin >> l >> r;
if (r - l + 1 >= cycle){
cout << cycle;
return 0;
}
l %= cycle;
r %= cycle;
if (l <= r){
addSegment(l, r);
} else {
addSegment(l, cycle - 1);
addSegment(0, r);
}
}
sort(e.begin(), e.end());
int cnt = 0;
ll res = 0, last = 0;
for(auto p : e){
if (p.first != last){
res += (cnt > 0) * (p.first - last);
last = p.first;
}
cnt += p.second;
}
cout << res;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
6 ms |
848 KB |
Output is correct |
3 |
Correct |
7 ms |
848 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
208 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 |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
208 KB |
Output is correct |
16 |
Correct |
6 ms |
976 KB |
Output is correct |
17 |
Correct |
66 ms |
4544 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
422 ms |
33168 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
581 ms |
33168 KB |
Output is correct |
3 |
Correct |
611 ms |
33288 KB |
Output is correct |
4 |
Correct |
587 ms |
69052 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
581 ms |
33168 KB |
Output is correct |
3 |
Correct |
611 ms |
33288 KB |
Output is correct |
4 |
Correct |
587 ms |
69052 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
622 ms |
69116 KB |
Output is correct |
7 |
Correct |
590 ms |
68920 KB |
Output is correct |
8 |
Correct |
601 ms |
69020 KB |
Output is correct |
9 |
Correct |
720 ms |
69108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
581 ms |
33168 KB |
Output is correct |
3 |
Correct |
611 ms |
33288 KB |
Output is correct |
4 |
Correct |
587 ms |
69052 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
58 ms |
7232 KB |
Output is correct |
7 |
Correct |
69 ms |
7316 KB |
Output is correct |
8 |
Correct |
66 ms |
7220 KB |
Output is correct |
9 |
Correct |
57 ms |
7212 KB |
Output is correct |
10 |
Correct |
55 ms |
7224 KB |
Output is correct |
11 |
Correct |
59 ms |
7264 KB |
Output is correct |
12 |
Correct |
63 ms |
7236 KB |
Output is correct |
13 |
Correct |
65 ms |
7232 KB |
Output is correct |
14 |
Correct |
58 ms |
7240 KB |
Output is correct |
15 |
Correct |
71 ms |
7180 KB |
Output is correct |
16 |
Correct |
66 ms |
7236 KB |
Output is correct |
17 |
Correct |
58 ms |
7272 KB |
Output is correct |
18 |
Correct |
638 ms |
68924 KB |
Output is correct |
19 |
Correct |
603 ms |
68948 KB |
Output is correct |
20 |
Correct |
759 ms |
68920 KB |
Output is correct |
21 |
Correct |
65 ms |
7268 KB |
Output is correct |
22 |
Correct |
53 ms |
7216 KB |
Output is correct |
23 |
Correct |
173 ms |
26900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
67 ms |
4520 KB |
Output is correct |
3 |
Correct |
69 ms |
4528 KB |
Output is correct |
4 |
Correct |
828 ms |
68932 KB |
Output is correct |
5 |
Correct |
62 ms |
7228 KB |
Output is correct |
6 |
Correct |
67 ms |
7308 KB |
Output is correct |
7 |
Correct |
73 ms |
7204 KB |
Output is correct |
8 |
Correct |
66 ms |
7280 KB |
Output is correct |
9 |
Correct |
61 ms |
7240 KB |
Output is correct |
10 |
Correct |
66 ms |
7248 KB |
Output is correct |
11 |
Correct |
64 ms |
7200 KB |
Output is correct |
12 |
Correct |
59 ms |
7236 KB |
Output is correct |
13 |
Correct |
66 ms |
7284 KB |
Output is correct |
14 |
Correct |
726 ms |
68888 KB |
Output is correct |
15 |
Correct |
67 ms |
7228 KB |
Output is correct |
16 |
Correct |
590 ms |
68968 KB |
Output is correct |
17 |
Correct |
634 ms |
68832 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
6 ms |
848 KB |
Output is correct |
3 |
Correct |
7 ms |
848 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
208 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 |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
208 KB |
Output is correct |
16 |
Correct |
6 ms |
976 KB |
Output is correct |
17 |
Correct |
66 ms |
4544 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 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 |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
422 ms |
33168 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
581 ms |
33168 KB |
Output is correct |
31 |
Correct |
611 ms |
33288 KB |
Output is correct |
32 |
Correct |
587 ms |
69052 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
622 ms |
69116 KB |
Output is correct |
35 |
Correct |
590 ms |
68920 KB |
Output is correct |
36 |
Correct |
601 ms |
69020 KB |
Output is correct |
37 |
Correct |
720 ms |
69108 KB |
Output is correct |
38 |
Correct |
1 ms |
204 KB |
Output is correct |
39 |
Correct |
58 ms |
7232 KB |
Output is correct |
40 |
Correct |
69 ms |
7316 KB |
Output is correct |
41 |
Correct |
66 ms |
7220 KB |
Output is correct |
42 |
Correct |
57 ms |
7212 KB |
Output is correct |
43 |
Correct |
55 ms |
7224 KB |
Output is correct |
44 |
Correct |
59 ms |
7264 KB |
Output is correct |
45 |
Correct |
63 ms |
7236 KB |
Output is correct |
46 |
Correct |
65 ms |
7232 KB |
Output is correct |
47 |
Correct |
58 ms |
7240 KB |
Output is correct |
48 |
Correct |
71 ms |
7180 KB |
Output is correct |
49 |
Correct |
66 ms |
7236 KB |
Output is correct |
50 |
Correct |
58 ms |
7272 KB |
Output is correct |
51 |
Correct |
638 ms |
68924 KB |
Output is correct |
52 |
Correct |
603 ms |
68948 KB |
Output is correct |
53 |
Correct |
759 ms |
68920 KB |
Output is correct |
54 |
Correct |
65 ms |
7268 KB |
Output is correct |
55 |
Correct |
53 ms |
7216 KB |
Output is correct |
56 |
Correct |
173 ms |
26900 KB |
Output is correct |
57 |
Correct |
1 ms |
204 KB |
Output is correct |
58 |
Correct |
67 ms |
4520 KB |
Output is correct |
59 |
Correct |
69 ms |
4528 KB |
Output is correct |
60 |
Correct |
828 ms |
68932 KB |
Output is correct |
61 |
Correct |
62 ms |
7228 KB |
Output is correct |
62 |
Correct |
67 ms |
7308 KB |
Output is correct |
63 |
Correct |
73 ms |
7204 KB |
Output is correct |
64 |
Correct |
66 ms |
7280 KB |
Output is correct |
65 |
Correct |
61 ms |
7240 KB |
Output is correct |
66 |
Correct |
66 ms |
7248 KB |
Output is correct |
67 |
Correct |
64 ms |
7200 KB |
Output is correct |
68 |
Correct |
59 ms |
7236 KB |
Output is correct |
69 |
Correct |
66 ms |
7284 KB |
Output is correct |
70 |
Correct |
726 ms |
68888 KB |
Output is correct |
71 |
Correct |
67 ms |
7228 KB |
Output is correct |
72 |
Correct |
590 ms |
68968 KB |
Output is correct |
73 |
Correct |
634 ms |
68832 KB |
Output is correct |
74 |
Correct |
1 ms |
204 KB |
Output is correct |
75 |
Correct |
1 ms |
204 KB |
Output is correct |
76 |
Correct |
1 ms |
312 KB |
Output is correct |
77 |
Correct |
1 ms |
316 KB |
Output is correct |
78 |
Correct |
1 ms |
204 KB |
Output is correct |
79 |
Correct |
6 ms |
1232 KB |
Output is correct |
80 |
Correct |
757 ms |
68984 KB |
Output is correct |
81 |
Correct |
781 ms |
68928 KB |
Output is correct |
82 |
Correct |
732 ms |
68880 KB |
Output is correct |
83 |
Correct |
708 ms |
68864 KB |
Output is correct |
84 |
Correct |
706 ms |
68856 KB |
Output is correct |
85 |
Correct |
711 ms |
68748 KB |
Output is correct |
86 |
Correct |
166 ms |
26660 KB |
Output is correct |
87 |
Correct |
1 ms |
332 KB |
Output is correct |