#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = (ll) 1e18;
ll n, a, b;
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
// freopen("input", stdin, "r");
cin >> n >> a >> b;
ll period = a / __gcd(b + 1, a);
if (INF / period < b) {
period = INF;
} else {
period *= b;
}
map<ll, int> jmen;
function<void(ll, ll)> add = [&](ll l, ll r) {
if (r - l + 1 >= period) {
jmen[0]++;
} else {
l %= period;
r %= period;
if (l <= r) {
jmen[l]++;
jmen[r + 1]--;
} else {
jmen[l]++;
jmen[period]--;
jmen[0]++;
jmen[r + 1]--;
}
}
};
for (int i = 1; i <= n; i++) {
ll l, r;
cin >> l >> r;
add(l, r);
}
jmen[period] = 0;
ll sol = 0;
int s = 0;
ll last = 0;
for (auto &i : jmen) {
if (s > 0) {
sol += i.first - last;
}
s += i.second;
last = i.first;
}
cout << sol << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
1236 KB |
Output is correct |
3 |
Correct |
5 ms |
1236 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
328 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
324 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
1224 KB |
Output is correct |
17 |
Correct |
53 ms |
10256 KB |
Output is correct |
18 |
Correct |
0 ms |
320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
292 KB |
Output is correct |
3 |
Correct |
1 ms |
212 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 |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
191 ms |
25372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
533 ms |
99972 KB |
Output is correct |
3 |
Correct |
542 ms |
99968 KB |
Output is correct |
4 |
Correct |
607 ms |
100040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
533 ms |
99972 KB |
Output is correct |
3 |
Correct |
542 ms |
99968 KB |
Output is correct |
4 |
Correct |
607 ms |
100040 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
557 ms |
100048 KB |
Output is correct |
7 |
Correct |
579 ms |
100176 KB |
Output is correct |
8 |
Correct |
539 ms |
99952 KB |
Output is correct |
9 |
Correct |
614 ms |
99944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
533 ms |
99972 KB |
Output is correct |
3 |
Correct |
542 ms |
99968 KB |
Output is correct |
4 |
Correct |
607 ms |
100040 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
51 ms |
10192 KB |
Output is correct |
7 |
Correct |
45 ms |
10236 KB |
Output is correct |
8 |
Correct |
49 ms |
10188 KB |
Output is correct |
9 |
Correct |
54 ms |
10188 KB |
Output is correct |
10 |
Correct |
47 ms |
10232 KB |
Output is correct |
11 |
Correct |
46 ms |
10200 KB |
Output is correct |
12 |
Correct |
48 ms |
10196 KB |
Output is correct |
13 |
Correct |
50 ms |
10224 KB |
Output is correct |
14 |
Correct |
45 ms |
10312 KB |
Output is correct |
15 |
Correct |
55 ms |
10280 KB |
Output is correct |
16 |
Correct |
56 ms |
10260 KB |
Output is correct |
17 |
Correct |
48 ms |
10280 KB |
Output is correct |
18 |
Correct |
567 ms |
100092 KB |
Output is correct |
19 |
Correct |
616 ms |
100036 KB |
Output is correct |
20 |
Correct |
598 ms |
100044 KB |
Output is correct |
21 |
Correct |
48 ms |
10184 KB |
Output is correct |
22 |
Correct |
49 ms |
10188 KB |
Output is correct |
23 |
Correct |
89 ms |
12840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
56 ms |
10196 KB |
Output is correct |
3 |
Correct |
52 ms |
10188 KB |
Output is correct |
4 |
Correct |
616 ms |
100056 KB |
Output is correct |
5 |
Correct |
54 ms |
10296 KB |
Output is correct |
6 |
Correct |
67 ms |
10288 KB |
Output is correct |
7 |
Correct |
55 ms |
10220 KB |
Output is correct |
8 |
Correct |
58 ms |
10240 KB |
Output is correct |
9 |
Correct |
51 ms |
10284 KB |
Output is correct |
10 |
Correct |
48 ms |
10240 KB |
Output is correct |
11 |
Correct |
49 ms |
10188 KB |
Output is correct |
12 |
Correct |
48 ms |
10188 KB |
Output is correct |
13 |
Correct |
53 ms |
10252 KB |
Output is correct |
14 |
Correct |
620 ms |
99992 KB |
Output is correct |
15 |
Correct |
47 ms |
10272 KB |
Output is correct |
16 |
Correct |
545 ms |
100020 KB |
Output is correct |
17 |
Correct |
539 ms |
99952 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
1236 KB |
Output is correct |
3 |
Correct |
5 ms |
1236 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
328 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
324 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
1224 KB |
Output is correct |
17 |
Correct |
53 ms |
10256 KB |
Output is correct |
18 |
Correct |
0 ms |
320 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
292 KB |
Output is correct |
21 |
Correct |
1 ms |
212 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 |
328 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
191 ms |
25372 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
533 ms |
99972 KB |
Output is correct |
31 |
Correct |
542 ms |
99968 KB |
Output is correct |
32 |
Correct |
607 ms |
100040 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
557 ms |
100048 KB |
Output is correct |
35 |
Correct |
579 ms |
100176 KB |
Output is correct |
36 |
Correct |
539 ms |
99952 KB |
Output is correct |
37 |
Correct |
614 ms |
99944 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
51 ms |
10192 KB |
Output is correct |
40 |
Correct |
45 ms |
10236 KB |
Output is correct |
41 |
Correct |
49 ms |
10188 KB |
Output is correct |
42 |
Correct |
54 ms |
10188 KB |
Output is correct |
43 |
Correct |
47 ms |
10232 KB |
Output is correct |
44 |
Correct |
46 ms |
10200 KB |
Output is correct |
45 |
Correct |
48 ms |
10196 KB |
Output is correct |
46 |
Correct |
50 ms |
10224 KB |
Output is correct |
47 |
Correct |
45 ms |
10312 KB |
Output is correct |
48 |
Correct |
55 ms |
10280 KB |
Output is correct |
49 |
Correct |
56 ms |
10260 KB |
Output is correct |
50 |
Correct |
48 ms |
10280 KB |
Output is correct |
51 |
Correct |
567 ms |
100092 KB |
Output is correct |
52 |
Correct |
616 ms |
100036 KB |
Output is correct |
53 |
Correct |
598 ms |
100044 KB |
Output is correct |
54 |
Correct |
48 ms |
10184 KB |
Output is correct |
55 |
Correct |
49 ms |
10188 KB |
Output is correct |
56 |
Correct |
89 ms |
12840 KB |
Output is correct |
57 |
Correct |
1 ms |
212 KB |
Output is correct |
58 |
Correct |
56 ms |
10196 KB |
Output is correct |
59 |
Correct |
52 ms |
10188 KB |
Output is correct |
60 |
Correct |
616 ms |
100056 KB |
Output is correct |
61 |
Correct |
54 ms |
10296 KB |
Output is correct |
62 |
Correct |
67 ms |
10288 KB |
Output is correct |
63 |
Correct |
55 ms |
10220 KB |
Output is correct |
64 |
Correct |
58 ms |
10240 KB |
Output is correct |
65 |
Correct |
51 ms |
10284 KB |
Output is correct |
66 |
Correct |
48 ms |
10240 KB |
Output is correct |
67 |
Correct |
49 ms |
10188 KB |
Output is correct |
68 |
Correct |
48 ms |
10188 KB |
Output is correct |
69 |
Correct |
53 ms |
10252 KB |
Output is correct |
70 |
Correct |
620 ms |
99992 KB |
Output is correct |
71 |
Correct |
47 ms |
10272 KB |
Output is correct |
72 |
Correct |
545 ms |
100020 KB |
Output is correct |
73 |
Correct |
539 ms |
99952 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 |
1 ms |
212 KB |
Output is correct |
78 |
Correct |
1 ms |
212 KB |
Output is correct |
79 |
Correct |
8 ms |
1300 KB |
Output is correct |
80 |
Correct |
569 ms |
65008 KB |
Output is correct |
81 |
Correct |
575 ms |
64948 KB |
Output is correct |
82 |
Correct |
577 ms |
64716 KB |
Output is correct |
83 |
Correct |
582 ms |
64828 KB |
Output is correct |
84 |
Correct |
594 ms |
65008 KB |
Output is correct |
85 |
Correct |
565 ms |
64972 KB |
Output is correct |
86 |
Correct |
85 ms |
12832 KB |
Output is correct |
87 |
Correct |
1 ms |
212 KB |
Output is correct |