#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint INF = 1e18 + 100;
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int n;
lint A, B;
cin >> n >> A >> B;
lint g = __gcd(A, B + 1);
lint t = 0;
if ((A / g) > ((INF + INF) / B)) {
t = INF;
} else {
t = (A / g) * B;
}
vector<pair<lint, lint>> interval;
for (int i = 0; i < n; i++) {
lint l, r;
cin >> l >> r;
if (r - l + 1 >= t) {
interval.emplace_back(0, t - 1);
} else {
l %= t, r %= t;
if (l <= r) {
interval.emplace_back(l, r);
} else {
interval.emplace_back(l, t - 1);
interval.emplace_back(0, r);
}
}
}
sort(begin(interval), end(interval));
lint ans = 0;
for (int i = 0; i < (int)interval.size(); i++) {
lint l = interval[i].first;
lint r = interval[i].second;
int nxt = i;
while (nxt + 1 < (int)interval.size() && interval[nxt + 1].first <= r) {
r = max(r, interval[nxt + 1].second);
nxt++;
}
ans += (r - l + 1);
i = nxt;
}
cout << ans << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
8 ms |
888 KB |
Output is correct |
3 |
Correct |
8 ms |
1016 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
8 ms |
1060 KB |
Output is correct |
17 |
Correct |
67 ms |
3056 KB |
Output is correct |
18 |
Correct |
2 ms |
380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
446 ms |
17096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
615 ms |
17300 KB |
Output is correct |
3 |
Correct |
598 ms |
16980 KB |
Output is correct |
4 |
Correct |
616 ms |
17148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
615 ms |
17300 KB |
Output is correct |
3 |
Correct |
598 ms |
16980 KB |
Output is correct |
4 |
Correct |
616 ms |
17148 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
599 ms |
17108 KB |
Output is correct |
7 |
Correct |
597 ms |
17100 KB |
Output is correct |
8 |
Correct |
607 ms |
17108 KB |
Output is correct |
9 |
Correct |
653 ms |
17108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
615 ms |
17300 KB |
Output is correct |
3 |
Correct |
598 ms |
16980 KB |
Output is correct |
4 |
Correct |
616 ms |
17148 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
60 ms |
2924 KB |
Output is correct |
7 |
Correct |
64 ms |
2900 KB |
Output is correct |
8 |
Correct |
61 ms |
2924 KB |
Output is correct |
9 |
Correct |
63 ms |
2924 KB |
Output is correct |
10 |
Correct |
60 ms |
2928 KB |
Output is correct |
11 |
Correct |
63 ms |
2896 KB |
Output is correct |
12 |
Correct |
60 ms |
2924 KB |
Output is correct |
13 |
Correct |
66 ms |
2964 KB |
Output is correct |
14 |
Correct |
60 ms |
2960 KB |
Output is correct |
15 |
Correct |
67 ms |
2924 KB |
Output is correct |
16 |
Correct |
66 ms |
2928 KB |
Output is correct |
17 |
Correct |
63 ms |
3052 KB |
Output is correct |
18 |
Correct |
602 ms |
16980 KB |
Output is correct |
19 |
Correct |
614 ms |
17152 KB |
Output is correct |
20 |
Correct |
674 ms |
17080 KB |
Output is correct |
21 |
Correct |
66 ms |
2928 KB |
Output is correct |
22 |
Correct |
59 ms |
2928 KB |
Output is correct |
23 |
Correct |
191 ms |
9100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
424 KB |
Output is correct |
2 |
Correct |
65 ms |
2796 KB |
Output is correct |
3 |
Correct |
65 ms |
2900 KB |
Output is correct |
4 |
Correct |
682 ms |
17156 KB |
Output is correct |
5 |
Correct |
66 ms |
2928 KB |
Output is correct |
6 |
Correct |
65 ms |
2928 KB |
Output is correct |
7 |
Correct |
65 ms |
2848 KB |
Output is correct |
8 |
Correct |
67 ms |
2932 KB |
Output is correct |
9 |
Correct |
66 ms |
3052 KB |
Output is correct |
10 |
Correct |
66 ms |
2940 KB |
Output is correct |
11 |
Correct |
67 ms |
3056 KB |
Output is correct |
12 |
Correct |
59 ms |
2928 KB |
Output is correct |
13 |
Correct |
66 ms |
2924 KB |
Output is correct |
14 |
Correct |
674 ms |
16980 KB |
Output is correct |
15 |
Correct |
67 ms |
2928 KB |
Output is correct |
16 |
Correct |
601 ms |
16984 KB |
Output is correct |
17 |
Correct |
600 ms |
17080 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
8 ms |
888 KB |
Output is correct |
3 |
Correct |
8 ms |
1016 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
8 ms |
1060 KB |
Output is correct |
17 |
Correct |
67 ms |
3056 KB |
Output is correct |
18 |
Correct |
2 ms |
380 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
3 ms |
376 KB |
Output is correct |
27 |
Correct |
3 ms |
376 KB |
Output is correct |
28 |
Correct |
446 ms |
17096 KB |
Output is correct |
29 |
Correct |
2 ms |
376 KB |
Output is correct |
30 |
Correct |
615 ms |
17300 KB |
Output is correct |
31 |
Correct |
598 ms |
16980 KB |
Output is correct |
32 |
Correct |
616 ms |
17148 KB |
Output is correct |
33 |
Correct |
2 ms |
376 KB |
Output is correct |
34 |
Correct |
599 ms |
17108 KB |
Output is correct |
35 |
Correct |
597 ms |
17100 KB |
Output is correct |
36 |
Correct |
607 ms |
17108 KB |
Output is correct |
37 |
Correct |
653 ms |
17108 KB |
Output is correct |
38 |
Correct |
2 ms |
376 KB |
Output is correct |
39 |
Correct |
60 ms |
2924 KB |
Output is correct |
40 |
Correct |
64 ms |
2900 KB |
Output is correct |
41 |
Correct |
61 ms |
2924 KB |
Output is correct |
42 |
Correct |
63 ms |
2924 KB |
Output is correct |
43 |
Correct |
60 ms |
2928 KB |
Output is correct |
44 |
Correct |
63 ms |
2896 KB |
Output is correct |
45 |
Correct |
60 ms |
2924 KB |
Output is correct |
46 |
Correct |
66 ms |
2964 KB |
Output is correct |
47 |
Correct |
60 ms |
2960 KB |
Output is correct |
48 |
Correct |
67 ms |
2924 KB |
Output is correct |
49 |
Correct |
66 ms |
2928 KB |
Output is correct |
50 |
Correct |
63 ms |
3052 KB |
Output is correct |
51 |
Correct |
602 ms |
16980 KB |
Output is correct |
52 |
Correct |
614 ms |
17152 KB |
Output is correct |
53 |
Correct |
674 ms |
17080 KB |
Output is correct |
54 |
Correct |
66 ms |
2928 KB |
Output is correct |
55 |
Correct |
59 ms |
2928 KB |
Output is correct |
56 |
Correct |
191 ms |
9100 KB |
Output is correct |
57 |
Correct |
2 ms |
424 KB |
Output is correct |
58 |
Correct |
65 ms |
2796 KB |
Output is correct |
59 |
Correct |
65 ms |
2900 KB |
Output is correct |
60 |
Correct |
682 ms |
17156 KB |
Output is correct |
61 |
Correct |
66 ms |
2928 KB |
Output is correct |
62 |
Correct |
65 ms |
2928 KB |
Output is correct |
63 |
Correct |
65 ms |
2848 KB |
Output is correct |
64 |
Correct |
67 ms |
2932 KB |
Output is correct |
65 |
Correct |
66 ms |
3052 KB |
Output is correct |
66 |
Correct |
66 ms |
2940 KB |
Output is correct |
67 |
Correct |
67 ms |
3056 KB |
Output is correct |
68 |
Correct |
59 ms |
2928 KB |
Output is correct |
69 |
Correct |
66 ms |
2924 KB |
Output is correct |
70 |
Correct |
674 ms |
16980 KB |
Output is correct |
71 |
Correct |
67 ms |
2928 KB |
Output is correct |
72 |
Correct |
601 ms |
16984 KB |
Output is correct |
73 |
Correct |
600 ms |
17080 KB |
Output is correct |
74 |
Correct |
2 ms |
376 KB |
Output is correct |
75 |
Correct |
2 ms |
376 KB |
Output is correct |
76 |
Correct |
2 ms |
376 KB |
Output is correct |
77 |
Correct |
2 ms |
376 KB |
Output is correct |
78 |
Correct |
2 ms |
376 KB |
Output is correct |
79 |
Correct |
8 ms |
1144 KB |
Output is correct |
80 |
Correct |
682 ms |
31276 KB |
Output is correct |
81 |
Correct |
698 ms |
31444 KB |
Output is correct |
82 |
Correct |
663 ms |
31316 KB |
Output is correct |
83 |
Correct |
692 ms |
31216 KB |
Output is correct |
84 |
Correct |
673 ms |
31356 KB |
Output is correct |
85 |
Correct |
657 ms |
31344 KB |
Output is correct |
86 |
Correct |
193 ms |
18528 KB |
Output is correct |
87 |
Correct |
2 ms |
376 KB |
Output is correct |