#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
constexpr LL INF = 1LL * 1e18;
int N;
LL A, B;
LL T;
map <long long, int> mp;
int main () {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> N >> A >> B;
A = A / __gcd(A, B+1);
if (A > INF / B) T = INF;
else T = A * B;
for (int i = 1; i <= N; ++ i ) {
LL L, R;
cin >> L >> R;
if (R - L + 1 >= T) {
cout << T << '\n';
return 0;
}
L = L % T;
R = R % T;
if (L <= R) {
mp[L] ++;
mp[(R+1)] --;
}
else {
mp[L] ++;
mp[T] --;
mp[0] ++;
mp[(R+1)] --;
}
}
LL last = 0;
int contor = 0;
LL ans = 0;
for (auto it : mp) {
ans += (it.first - last) * (contor != 0);
contor += it.second;
last = it.first;
}
cout << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
6 ms |
1224 KB |
Output is correct |
3 |
Correct |
6 ms |
1320 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
320 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 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 |
316 KB |
Output is correct |
15 |
Correct |
1 ms |
252 KB |
Output is correct |
16 |
Correct |
6 ms |
1268 KB |
Output is correct |
17 |
Correct |
63 ms |
10276 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
253 ms |
25368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
628 ms |
100068 KB |
Output is correct |
3 |
Correct |
681 ms |
83588 KB |
Output is correct |
4 |
Correct |
739 ms |
100092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
628 ms |
100068 KB |
Output is correct |
3 |
Correct |
681 ms |
83588 KB |
Output is correct |
4 |
Correct |
739 ms |
100092 KB |
Output is correct |
5 |
Correct |
0 ms |
316 KB |
Output is correct |
6 |
Correct |
650 ms |
99968 KB |
Output is correct |
7 |
Correct |
650 ms |
100024 KB |
Output is correct |
8 |
Correct |
652 ms |
99960 KB |
Output is correct |
9 |
Correct |
782 ms |
100020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
628 ms |
100068 KB |
Output is correct |
3 |
Correct |
681 ms |
83588 KB |
Output is correct |
4 |
Correct |
739 ms |
100092 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
54 ms |
10220 KB |
Output is correct |
7 |
Correct |
57 ms |
10268 KB |
Output is correct |
8 |
Correct |
57 ms |
10200 KB |
Output is correct |
9 |
Correct |
60 ms |
10172 KB |
Output is correct |
10 |
Correct |
53 ms |
10272 KB |
Output is correct |
11 |
Correct |
53 ms |
10188 KB |
Output is correct |
12 |
Correct |
57 ms |
10184 KB |
Output is correct |
13 |
Correct |
61 ms |
10180 KB |
Output is correct |
14 |
Correct |
53 ms |
10416 KB |
Output is correct |
15 |
Correct |
65 ms |
10244 KB |
Output is correct |
16 |
Correct |
77 ms |
10316 KB |
Output is correct |
17 |
Correct |
59 ms |
10188 KB |
Output is correct |
18 |
Correct |
616 ms |
100116 KB |
Output is correct |
19 |
Correct |
719 ms |
100008 KB |
Output is correct |
20 |
Correct |
798 ms |
100044 KB |
Output is correct |
21 |
Correct |
56 ms |
10292 KB |
Output is correct |
22 |
Correct |
56 ms |
10308 KB |
Output is correct |
23 |
Correct |
106 ms |
12832 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
71 ms |
10184 KB |
Output is correct |
3 |
Correct |
63 ms |
10208 KB |
Output is correct |
4 |
Correct |
725 ms |
100172 KB |
Output is correct |
5 |
Correct |
66 ms |
10272 KB |
Output is correct |
6 |
Correct |
68 ms |
10188 KB |
Output is correct |
7 |
Correct |
65 ms |
10212 KB |
Output is correct |
8 |
Correct |
67 ms |
10184 KB |
Output is correct |
9 |
Correct |
65 ms |
10180 KB |
Output is correct |
10 |
Correct |
58 ms |
10188 KB |
Output is correct |
11 |
Correct |
60 ms |
10296 KB |
Output is correct |
12 |
Correct |
59 ms |
10272 KB |
Output is correct |
13 |
Correct |
71 ms |
10244 KB |
Output is correct |
14 |
Correct |
846 ms |
100256 KB |
Output is correct |
15 |
Correct |
54 ms |
10300 KB |
Output is correct |
16 |
Correct |
646 ms |
83200 KB |
Output is correct |
17 |
Correct |
639 ms |
83132 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
6 ms |
1224 KB |
Output is correct |
3 |
Correct |
6 ms |
1320 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
320 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 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 |
316 KB |
Output is correct |
15 |
Correct |
1 ms |
252 KB |
Output is correct |
16 |
Correct |
6 ms |
1268 KB |
Output is correct |
17 |
Correct |
63 ms |
10276 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
316 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
328 KB |
Output is correct |
23 |
Correct |
1 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 |
253 ms |
25368 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
628 ms |
100068 KB |
Output is correct |
31 |
Correct |
681 ms |
83588 KB |
Output is correct |
32 |
Correct |
739 ms |
100092 KB |
Output is correct |
33 |
Correct |
0 ms |
316 KB |
Output is correct |
34 |
Correct |
650 ms |
99968 KB |
Output is correct |
35 |
Correct |
650 ms |
100024 KB |
Output is correct |
36 |
Correct |
652 ms |
99960 KB |
Output is correct |
37 |
Correct |
782 ms |
100020 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
54 ms |
10220 KB |
Output is correct |
40 |
Correct |
57 ms |
10268 KB |
Output is correct |
41 |
Correct |
57 ms |
10200 KB |
Output is correct |
42 |
Correct |
60 ms |
10172 KB |
Output is correct |
43 |
Correct |
53 ms |
10272 KB |
Output is correct |
44 |
Correct |
53 ms |
10188 KB |
Output is correct |
45 |
Correct |
57 ms |
10184 KB |
Output is correct |
46 |
Correct |
61 ms |
10180 KB |
Output is correct |
47 |
Correct |
53 ms |
10416 KB |
Output is correct |
48 |
Correct |
65 ms |
10244 KB |
Output is correct |
49 |
Correct |
77 ms |
10316 KB |
Output is correct |
50 |
Correct |
59 ms |
10188 KB |
Output is correct |
51 |
Correct |
616 ms |
100116 KB |
Output is correct |
52 |
Correct |
719 ms |
100008 KB |
Output is correct |
53 |
Correct |
798 ms |
100044 KB |
Output is correct |
54 |
Correct |
56 ms |
10292 KB |
Output is correct |
55 |
Correct |
56 ms |
10308 KB |
Output is correct |
56 |
Correct |
106 ms |
12832 KB |
Output is correct |
57 |
Correct |
0 ms |
212 KB |
Output is correct |
58 |
Correct |
71 ms |
10184 KB |
Output is correct |
59 |
Correct |
63 ms |
10208 KB |
Output is correct |
60 |
Correct |
725 ms |
100172 KB |
Output is correct |
61 |
Correct |
66 ms |
10272 KB |
Output is correct |
62 |
Correct |
68 ms |
10188 KB |
Output is correct |
63 |
Correct |
65 ms |
10212 KB |
Output is correct |
64 |
Correct |
67 ms |
10184 KB |
Output is correct |
65 |
Correct |
65 ms |
10180 KB |
Output is correct |
66 |
Correct |
58 ms |
10188 KB |
Output is correct |
67 |
Correct |
60 ms |
10296 KB |
Output is correct |
68 |
Correct |
59 ms |
10272 KB |
Output is correct |
69 |
Correct |
71 ms |
10244 KB |
Output is correct |
70 |
Correct |
846 ms |
100256 KB |
Output is correct |
71 |
Correct |
54 ms |
10300 KB |
Output is correct |
72 |
Correct |
646 ms |
83200 KB |
Output is correct |
73 |
Correct |
639 ms |
83132 KB |
Output is correct |
74 |
Correct |
0 ms |
212 KB |
Output is correct |
75 |
Correct |
1 ms |
316 KB |
Output is correct |
76 |
Correct |
0 ms |
212 KB |
Output is correct |
77 |
Correct |
1 ms |
212 KB |
Output is correct |
78 |
Correct |
0 ms |
212 KB |
Output is correct |
79 |
Correct |
6 ms |
1320 KB |
Output is correct |
80 |
Correct |
718 ms |
100192 KB |
Output is correct |
81 |
Correct |
736 ms |
100056 KB |
Output is correct |
82 |
Correct |
696 ms |
100048 KB |
Output is correct |
83 |
Correct |
727 ms |
100152 KB |
Output is correct |
84 |
Correct |
767 ms |
100272 KB |
Output is correct |
85 |
Correct |
704 ms |
100108 KB |
Output is correct |
86 |
Correct |
106 ms |
12832 KB |
Output is correct |
87 |
Correct |
0 ms |
324 KB |
Output is correct |