#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
const ll INF = 1e18;
ll N, A, B, T;
ll sweep(vector<pll> &v) {
ll l = 0, r = -1, ret = 0;
for(auto line : v) {
if(r >= line.first) r = max(r, line.second);
else {
ret += (r - l + 1);
l = line.first, r = line.second;
}
}
return ret + (r - l + 1);
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> N >> A >> B;
T = A / __gcd(A, B+1);
if(INF / A + 1 < B) T = INF;
else T *= B, T = min(T, INF);
vector<pll> line;
for(int i=1; i<=N; i++) {
ll a, b; cin >> a >> b;
if(b - a >= T) {
cout << T;
return 0;
}
a %= T; b %= T;
if(a > b) {
line.push_back(pll(a, T-1));
line.push_back(pll(0, b));
}
else line.push_back(pll(a, b));
}
sort(line.begin(), line.end());
line.erase(unique(line.begin(), line.end()), line.end());
cout << sweep(line);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
8 ms |
1016 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 |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 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 |
380 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
9 ms |
1016 KB |
Output is correct |
17 |
Correct |
68 ms |
3052 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
296 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 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 |
457 ms |
17360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
610 ms |
17476 KB |
Output is correct |
3 |
Correct |
611 ms |
17232 KB |
Output is correct |
4 |
Correct |
608 ms |
17152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
610 ms |
17476 KB |
Output is correct |
3 |
Correct |
611 ms |
17232 KB |
Output is correct |
4 |
Correct |
608 ms |
17152 KB |
Output is correct |
5 |
Correct |
2 ms |
380 KB |
Output is correct |
6 |
Correct |
603 ms |
17160 KB |
Output is correct |
7 |
Correct |
602 ms |
17264 KB |
Output is correct |
8 |
Correct |
614 ms |
17188 KB |
Output is correct |
9 |
Correct |
659 ms |
17336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
610 ms |
17476 KB |
Output is correct |
3 |
Correct |
611 ms |
17232 KB |
Output is correct |
4 |
Correct |
608 ms |
17152 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
60 ms |
2796 KB |
Output is correct |
7 |
Correct |
65 ms |
2760 KB |
Output is correct |
8 |
Correct |
62 ms |
2748 KB |
Output is correct |
9 |
Correct |
64 ms |
3056 KB |
Output is correct |
10 |
Correct |
61 ms |
3052 KB |
Output is correct |
11 |
Correct |
65 ms |
3056 KB |
Output is correct |
12 |
Correct |
62 ms |
3056 KB |
Output is correct |
13 |
Correct |
68 ms |
2944 KB |
Output is correct |
14 |
Correct |
61 ms |
2796 KB |
Output is correct |
15 |
Correct |
69 ms |
2848 KB |
Output is correct |
16 |
Correct |
67 ms |
2700 KB |
Output is correct |
17 |
Correct |
64 ms |
2796 KB |
Output is correct |
18 |
Correct |
609 ms |
16980 KB |
Output is correct |
19 |
Correct |
599 ms |
17212 KB |
Output is correct |
20 |
Correct |
670 ms |
17108 KB |
Output is correct |
21 |
Correct |
67 ms |
3056 KB |
Output is correct |
22 |
Correct |
57 ms |
3056 KB |
Output is correct |
23 |
Correct |
197 ms |
9768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
66 ms |
2932 KB |
Output is correct |
3 |
Correct |
67 ms |
2744 KB |
Output is correct |
4 |
Correct |
687 ms |
16992 KB |
Output is correct |
5 |
Correct |
66 ms |
2872 KB |
Output is correct |
6 |
Correct |
66 ms |
2792 KB |
Output is correct |
7 |
Correct |
67 ms |
2772 KB |
Output is correct |
8 |
Correct |
67 ms |
2788 KB |
Output is correct |
9 |
Correct |
65 ms |
2744 KB |
Output is correct |
10 |
Correct |
66 ms |
2820 KB |
Output is correct |
11 |
Correct |
66 ms |
2640 KB |
Output is correct |
12 |
Correct |
61 ms |
2544 KB |
Output is correct |
13 |
Correct |
66 ms |
2580 KB |
Output is correct |
14 |
Correct |
660 ms |
16952 KB |
Output is correct |
15 |
Correct |
68 ms |
2756 KB |
Output is correct |
16 |
Correct |
621 ms |
17004 KB |
Output is correct |
17 |
Correct |
598 ms |
17172 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
8 ms |
1016 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 |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 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 |
380 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
9 ms |
1016 KB |
Output is correct |
17 |
Correct |
68 ms |
3052 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
256 KB |
Output is correct |
20 |
Correct |
2 ms |
256 KB |
Output is correct |
21 |
Correct |
2 ms |
296 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 |
3 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 |
457 ms |
17360 KB |
Output is correct |
29 |
Correct |
2 ms |
376 KB |
Output is correct |
30 |
Correct |
610 ms |
17476 KB |
Output is correct |
31 |
Correct |
611 ms |
17232 KB |
Output is correct |
32 |
Correct |
608 ms |
17152 KB |
Output is correct |
33 |
Correct |
2 ms |
380 KB |
Output is correct |
34 |
Correct |
603 ms |
17160 KB |
Output is correct |
35 |
Correct |
602 ms |
17264 KB |
Output is correct |
36 |
Correct |
614 ms |
17188 KB |
Output is correct |
37 |
Correct |
659 ms |
17336 KB |
Output is correct |
38 |
Correct |
2 ms |
384 KB |
Output is correct |
39 |
Correct |
60 ms |
2796 KB |
Output is correct |
40 |
Correct |
65 ms |
2760 KB |
Output is correct |
41 |
Correct |
62 ms |
2748 KB |
Output is correct |
42 |
Correct |
64 ms |
3056 KB |
Output is correct |
43 |
Correct |
61 ms |
3052 KB |
Output is correct |
44 |
Correct |
65 ms |
3056 KB |
Output is correct |
45 |
Correct |
62 ms |
3056 KB |
Output is correct |
46 |
Correct |
68 ms |
2944 KB |
Output is correct |
47 |
Correct |
61 ms |
2796 KB |
Output is correct |
48 |
Correct |
69 ms |
2848 KB |
Output is correct |
49 |
Correct |
67 ms |
2700 KB |
Output is correct |
50 |
Correct |
64 ms |
2796 KB |
Output is correct |
51 |
Correct |
609 ms |
16980 KB |
Output is correct |
52 |
Correct |
599 ms |
17212 KB |
Output is correct |
53 |
Correct |
670 ms |
17108 KB |
Output is correct |
54 |
Correct |
67 ms |
3056 KB |
Output is correct |
55 |
Correct |
57 ms |
3056 KB |
Output is correct |
56 |
Correct |
197 ms |
9768 KB |
Output is correct |
57 |
Correct |
2 ms |
376 KB |
Output is correct |
58 |
Correct |
66 ms |
2932 KB |
Output is correct |
59 |
Correct |
67 ms |
2744 KB |
Output is correct |
60 |
Correct |
687 ms |
16992 KB |
Output is correct |
61 |
Correct |
66 ms |
2872 KB |
Output is correct |
62 |
Correct |
66 ms |
2792 KB |
Output is correct |
63 |
Correct |
67 ms |
2772 KB |
Output is correct |
64 |
Correct |
67 ms |
2788 KB |
Output is correct |
65 |
Correct |
65 ms |
2744 KB |
Output is correct |
66 |
Correct |
66 ms |
2820 KB |
Output is correct |
67 |
Correct |
66 ms |
2640 KB |
Output is correct |
68 |
Correct |
61 ms |
2544 KB |
Output is correct |
69 |
Correct |
66 ms |
2580 KB |
Output is correct |
70 |
Correct |
660 ms |
16952 KB |
Output is correct |
71 |
Correct |
68 ms |
2756 KB |
Output is correct |
72 |
Correct |
621 ms |
17004 KB |
Output is correct |
73 |
Correct |
598 ms |
17172 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 |
504 KB |
Output is correct |
78 |
Correct |
2 ms |
380 KB |
Output is correct |
79 |
Correct |
8 ms |
1272 KB |
Output is correct |
80 |
Correct |
683 ms |
18516 KB |
Output is correct |
81 |
Correct |
680 ms |
18600 KB |
Output is correct |
82 |
Correct |
659 ms |
18516 KB |
Output is correct |
83 |
Correct |
658 ms |
18536 KB |
Output is correct |
84 |
Correct |
661 ms |
18616 KB |
Output is correct |
85 |
Correct |
660 ms |
18708 KB |
Output is correct |
86 |
Correct |
194 ms |
13500 KB |
Output is correct |
87 |
Correct |
2 ms |
376 KB |
Output is correct |