#include <bits/stdc++.h>
using namespace std;
const long long INF = 2e18;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int N;
long long A, B;
cin >> N >> A >> B;
long long AI = A / gcd(A, B + 1);
long long M = INF / AI >= B ? AI * B : INF;
vector<pair<long long, int>> events;
for (int i = 0; i < N; i++) {
long long L, R;
cin >> L >> R;
if (R - L >= M) {
cout << M << "\n";
exit(0);
}
if (R % M < L % M) {
events.push_back({L % M, 1});
events.push_back({M, -1});
events.push_back({0, 1});
events.push_back({R % M + 1, -1});
} else {
events.push_back({L % M, 1});
events.push_back({R % M + 1, -1});
}
}
sort(events.begin(), events.end());
long long ans = 0, last = 0;
int open = 0;
for (auto [x, type] : events) {
if (open != 0) {
ans += x - last;
}
open += type;
last = x;
}
cout << ans << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
4 ms |
856 KB |
Output is correct |
3 |
Correct |
4 ms |
856 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
232 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
336 KB |
Output is correct |
16 |
Correct |
4 ms |
984 KB |
Output is correct |
17 |
Correct |
44 ms |
4508 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
284 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
320 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 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 |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
266 ms |
56880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
393 ms |
33296 KB |
Output is correct |
3 |
Correct |
410 ms |
68980 KB |
Output is correct |
4 |
Correct |
379 ms |
68988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
393 ms |
33296 KB |
Output is correct |
3 |
Correct |
410 ms |
68980 KB |
Output is correct |
4 |
Correct |
379 ms |
68988 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
438 ms |
68868 KB |
Output is correct |
7 |
Correct |
385 ms |
68940 KB |
Output is correct |
8 |
Correct |
393 ms |
68844 KB |
Output is correct |
9 |
Correct |
456 ms |
68932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
393 ms |
33296 KB |
Output is correct |
3 |
Correct |
410 ms |
68980 KB |
Output is correct |
4 |
Correct |
379 ms |
68988 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
42 ms |
7204 KB |
Output is correct |
7 |
Correct |
40 ms |
7288 KB |
Output is correct |
8 |
Correct |
40 ms |
7248 KB |
Output is correct |
9 |
Correct |
38 ms |
7408 KB |
Output is correct |
10 |
Correct |
38 ms |
7264 KB |
Output is correct |
11 |
Correct |
38 ms |
7236 KB |
Output is correct |
12 |
Correct |
36 ms |
7296 KB |
Output is correct |
13 |
Correct |
41 ms |
7208 KB |
Output is correct |
14 |
Correct |
37 ms |
7196 KB |
Output is correct |
15 |
Correct |
44 ms |
7312 KB |
Output is correct |
16 |
Correct |
44 ms |
7240 KB |
Output is correct |
17 |
Correct |
37 ms |
7236 KB |
Output is correct |
18 |
Correct |
431 ms |
68880 KB |
Output is correct |
19 |
Correct |
389 ms |
68872 KB |
Output is correct |
20 |
Correct |
471 ms |
68952 KB |
Output is correct |
21 |
Correct |
44 ms |
7236 KB |
Output is correct |
22 |
Correct |
34 ms |
7244 KB |
Output is correct |
23 |
Correct |
110 ms |
26684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
43 ms |
4560 KB |
Output is correct |
3 |
Correct |
45 ms |
7244 KB |
Output is correct |
4 |
Correct |
630 ms |
68876 KB |
Output is correct |
5 |
Correct |
41 ms |
7220 KB |
Output is correct |
6 |
Correct |
41 ms |
7280 KB |
Output is correct |
7 |
Correct |
44 ms |
7248 KB |
Output is correct |
8 |
Correct |
45 ms |
7228 KB |
Output is correct |
9 |
Correct |
40 ms |
7280 KB |
Output is correct |
10 |
Correct |
43 ms |
7292 KB |
Output is correct |
11 |
Correct |
43 ms |
7240 KB |
Output is correct |
12 |
Correct |
40 ms |
7264 KB |
Output is correct |
13 |
Correct |
43 ms |
7264 KB |
Output is correct |
14 |
Correct |
454 ms |
68976 KB |
Output is correct |
15 |
Correct |
44 ms |
7240 KB |
Output is correct |
16 |
Correct |
373 ms |
68888 KB |
Output is correct |
17 |
Correct |
406 ms |
68880 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 |
4 ms |
856 KB |
Output is correct |
3 |
Correct |
4 ms |
856 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
232 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
336 KB |
Output is correct |
16 |
Correct |
4 ms |
984 KB |
Output is correct |
17 |
Correct |
44 ms |
4508 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
284 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
320 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
266 ms |
56880 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
393 ms |
33296 KB |
Output is correct |
31 |
Correct |
410 ms |
68980 KB |
Output is correct |
32 |
Correct |
379 ms |
68988 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
438 ms |
68868 KB |
Output is correct |
35 |
Correct |
385 ms |
68940 KB |
Output is correct |
36 |
Correct |
393 ms |
68844 KB |
Output is correct |
37 |
Correct |
456 ms |
68932 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
42 ms |
7204 KB |
Output is correct |
40 |
Correct |
40 ms |
7288 KB |
Output is correct |
41 |
Correct |
40 ms |
7248 KB |
Output is correct |
42 |
Correct |
38 ms |
7408 KB |
Output is correct |
43 |
Correct |
38 ms |
7264 KB |
Output is correct |
44 |
Correct |
38 ms |
7236 KB |
Output is correct |
45 |
Correct |
36 ms |
7296 KB |
Output is correct |
46 |
Correct |
41 ms |
7208 KB |
Output is correct |
47 |
Correct |
37 ms |
7196 KB |
Output is correct |
48 |
Correct |
44 ms |
7312 KB |
Output is correct |
49 |
Correct |
44 ms |
7240 KB |
Output is correct |
50 |
Correct |
37 ms |
7236 KB |
Output is correct |
51 |
Correct |
431 ms |
68880 KB |
Output is correct |
52 |
Correct |
389 ms |
68872 KB |
Output is correct |
53 |
Correct |
471 ms |
68952 KB |
Output is correct |
54 |
Correct |
44 ms |
7236 KB |
Output is correct |
55 |
Correct |
34 ms |
7244 KB |
Output is correct |
56 |
Correct |
110 ms |
26684 KB |
Output is correct |
57 |
Correct |
0 ms |
212 KB |
Output is correct |
58 |
Correct |
43 ms |
4560 KB |
Output is correct |
59 |
Correct |
45 ms |
7244 KB |
Output is correct |
60 |
Correct |
630 ms |
68876 KB |
Output is correct |
61 |
Correct |
41 ms |
7220 KB |
Output is correct |
62 |
Correct |
41 ms |
7280 KB |
Output is correct |
63 |
Correct |
44 ms |
7248 KB |
Output is correct |
64 |
Correct |
45 ms |
7228 KB |
Output is correct |
65 |
Correct |
40 ms |
7280 KB |
Output is correct |
66 |
Correct |
43 ms |
7292 KB |
Output is correct |
67 |
Correct |
43 ms |
7240 KB |
Output is correct |
68 |
Correct |
40 ms |
7264 KB |
Output is correct |
69 |
Correct |
43 ms |
7264 KB |
Output is correct |
70 |
Correct |
454 ms |
68976 KB |
Output is correct |
71 |
Correct |
44 ms |
7240 KB |
Output is correct |
72 |
Correct |
373 ms |
68888 KB |
Output is correct |
73 |
Correct |
406 ms |
68880 KB |
Output is correct |
74 |
Correct |
1 ms |
212 KB |
Output is correct |
75 |
Correct |
1 ms |
212 KB |
Output is correct |
76 |
Correct |
1 ms |
212 KB |
Output is correct |
77 |
Correct |
0 ms |
212 KB |
Output is correct |
78 |
Correct |
0 ms |
212 KB |
Output is correct |
79 |
Correct |
4 ms |
1368 KB |
Output is correct |
80 |
Correct |
539 ms |
68924 KB |
Output is correct |
81 |
Correct |
563 ms |
68944 KB |
Output is correct |
82 |
Correct |
508 ms |
68872 KB |
Output is correct |
83 |
Correct |
456 ms |
68888 KB |
Output is correct |
84 |
Correct |
463 ms |
68928 KB |
Output is correct |
85 |
Correct |
473 ms |
68908 KB |
Output is correct |
86 |
Correct |
107 ms |
26728 KB |
Output is correct |
87 |
Correct |
0 ms |
212 KB |
Output is correct |