#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lll __int128_t
#define flt double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
lll gcd(lll a, lll b) {
while (a != 0) {
b %= a;
swap(a, b);
}
return b;
}
int32_t main() {
if (1) {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int n;
ll A, B;
cin >> n >> A >> B;
lll t = (lll)(B) * (A / gcd(A, B + 1));
vector<pair<ll, int>> f;
f.reserve(n * 4);
for (int i = 0; i < n; i += 1) {
ll l, r;
cin >> l >> r;
r += 1;
if (r - l >= t) {
f.push_back(make_pair(0, 1));
f.push_back(make_pair(t, -1));
continue;
}
ll nl = l % t;
ll nr = r % t;
if (nl < nr) {
f.push_back(make_pair(nl, 1));
f.push_back(make_pair(nr, -1));
continue;
}
f.push_back(make_pair(nl, 1));
f.push_back(make_pair(t, -1));
f.push_back(make_pair(0, 1));
f.push_back(make_pair(nr, -1));
}
sort(all(f));
ll count = 0;
ll biba = 0;
for (int i = 0; i + 1 < (int)f.size(); i += 1) {
biba += f[i].second;
if (biba > 0) {
count += f[i + 1].first - f[i].first;
}
}
cout << count << "\n";
/*
vector<ll> usd(t, 0);
for (int i = 0; i < n; i += 1) {
ll l, r;
cin >> l >> r;
for (int j = l; j <= r; j += 1) {
usd[j % t] = 1;
}
}
ll count = 0;
for (int j = 0; j < t; j += 1) {
count += usd[j];
}
cout << count << "\n";
*/
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
4 ms |
980 KB |
Output is correct |
3 |
Correct |
5 ms |
920 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
316 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 |
1 ms |
316 KB |
Output is correct |
11 |
Correct |
1 ms |
320 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 |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
1012 KB |
Output is correct |
17 |
Correct |
70 ms |
7028 KB |
Output is correct |
18 |
Correct |
1 ms |
320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
320 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
324 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 |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
266 ms |
41360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
436 ms |
43948 KB |
Output is correct |
3 |
Correct |
429 ms |
43888 KB |
Output is correct |
4 |
Correct |
425 ms |
43896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
436 ms |
43948 KB |
Output is correct |
3 |
Correct |
429 ms |
43888 KB |
Output is correct |
4 |
Correct |
425 ms |
43896 KB |
Output is correct |
5 |
Correct |
1 ms |
216 KB |
Output is correct |
6 |
Correct |
433 ms |
43984 KB |
Output is correct |
7 |
Correct |
472 ms |
43900 KB |
Output is correct |
8 |
Correct |
435 ms |
43940 KB |
Output is correct |
9 |
Correct |
507 ms |
44056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
436 ms |
43948 KB |
Output is correct |
3 |
Correct |
429 ms |
43888 KB |
Output is correct |
4 |
Correct |
425 ms |
43896 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
47 ms |
7128 KB |
Output is correct |
7 |
Correct |
49 ms |
7104 KB |
Output is correct |
8 |
Correct |
57 ms |
7148 KB |
Output is correct |
9 |
Correct |
43 ms |
7152 KB |
Output is correct |
10 |
Correct |
36 ms |
7052 KB |
Output is correct |
11 |
Correct |
39 ms |
7092 KB |
Output is correct |
12 |
Correct |
38 ms |
7108 KB |
Output is correct |
13 |
Correct |
53 ms |
7056 KB |
Output is correct |
14 |
Correct |
37 ms |
7028 KB |
Output is correct |
15 |
Correct |
46 ms |
7112 KB |
Output is correct |
16 |
Correct |
46 ms |
7068 KB |
Output is correct |
17 |
Correct |
39 ms |
7116 KB |
Output is correct |
18 |
Correct |
417 ms |
43888 KB |
Output is correct |
19 |
Correct |
406 ms |
43984 KB |
Output is correct |
20 |
Correct |
493 ms |
43980 KB |
Output is correct |
21 |
Correct |
45 ms |
7032 KB |
Output is correct |
22 |
Correct |
40 ms |
7120 KB |
Output is correct |
23 |
Correct |
100 ms |
23448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
43 ms |
7080 KB |
Output is correct |
3 |
Correct |
43 ms |
7116 KB |
Output is correct |
4 |
Correct |
566 ms |
68608 KB |
Output is correct |
5 |
Correct |
42 ms |
7140 KB |
Output is correct |
6 |
Correct |
44 ms |
7144 KB |
Output is correct |
7 |
Correct |
49 ms |
7140 KB |
Output is correct |
8 |
Correct |
45 ms |
7132 KB |
Output is correct |
9 |
Correct |
43 ms |
7036 KB |
Output is correct |
10 |
Correct |
53 ms |
7048 KB |
Output is correct |
11 |
Correct |
48 ms |
7056 KB |
Output is correct |
12 |
Correct |
41 ms |
7108 KB |
Output is correct |
13 |
Correct |
55 ms |
7052 KB |
Output is correct |
14 |
Correct |
475 ms |
68704 KB |
Output is correct |
15 |
Correct |
59 ms |
7092 KB |
Output is correct |
16 |
Correct |
395 ms |
68724 KB |
Output is correct |
17 |
Correct |
402 ms |
68696 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
4 ms |
980 KB |
Output is correct |
3 |
Correct |
5 ms |
920 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
316 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 |
1 ms |
316 KB |
Output is correct |
11 |
Correct |
1 ms |
320 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 |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
1012 KB |
Output is correct |
17 |
Correct |
70 ms |
7028 KB |
Output is correct |
18 |
Correct |
1 ms |
320 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
320 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
324 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 |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
266 ms |
41360 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
436 ms |
43948 KB |
Output is correct |
31 |
Correct |
429 ms |
43888 KB |
Output is correct |
32 |
Correct |
425 ms |
43896 KB |
Output is correct |
33 |
Correct |
1 ms |
216 KB |
Output is correct |
34 |
Correct |
433 ms |
43984 KB |
Output is correct |
35 |
Correct |
472 ms |
43900 KB |
Output is correct |
36 |
Correct |
435 ms |
43940 KB |
Output is correct |
37 |
Correct |
507 ms |
44056 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
47 ms |
7128 KB |
Output is correct |
40 |
Correct |
49 ms |
7104 KB |
Output is correct |
41 |
Correct |
57 ms |
7148 KB |
Output is correct |
42 |
Correct |
43 ms |
7152 KB |
Output is correct |
43 |
Correct |
36 ms |
7052 KB |
Output is correct |
44 |
Correct |
39 ms |
7092 KB |
Output is correct |
45 |
Correct |
38 ms |
7108 KB |
Output is correct |
46 |
Correct |
53 ms |
7056 KB |
Output is correct |
47 |
Correct |
37 ms |
7028 KB |
Output is correct |
48 |
Correct |
46 ms |
7112 KB |
Output is correct |
49 |
Correct |
46 ms |
7068 KB |
Output is correct |
50 |
Correct |
39 ms |
7116 KB |
Output is correct |
51 |
Correct |
417 ms |
43888 KB |
Output is correct |
52 |
Correct |
406 ms |
43984 KB |
Output is correct |
53 |
Correct |
493 ms |
43980 KB |
Output is correct |
54 |
Correct |
45 ms |
7032 KB |
Output is correct |
55 |
Correct |
40 ms |
7120 KB |
Output is correct |
56 |
Correct |
100 ms |
23448 KB |
Output is correct |
57 |
Correct |
0 ms |
212 KB |
Output is correct |
58 |
Correct |
43 ms |
7080 KB |
Output is correct |
59 |
Correct |
43 ms |
7116 KB |
Output is correct |
60 |
Correct |
566 ms |
68608 KB |
Output is correct |
61 |
Correct |
42 ms |
7140 KB |
Output is correct |
62 |
Correct |
44 ms |
7144 KB |
Output is correct |
63 |
Correct |
49 ms |
7140 KB |
Output is correct |
64 |
Correct |
45 ms |
7132 KB |
Output is correct |
65 |
Correct |
43 ms |
7036 KB |
Output is correct |
66 |
Correct |
53 ms |
7048 KB |
Output is correct |
67 |
Correct |
48 ms |
7056 KB |
Output is correct |
68 |
Correct |
41 ms |
7108 KB |
Output is correct |
69 |
Correct |
55 ms |
7052 KB |
Output is correct |
70 |
Correct |
475 ms |
68704 KB |
Output is correct |
71 |
Correct |
59 ms |
7092 KB |
Output is correct |
72 |
Correct |
395 ms |
68724 KB |
Output is correct |
73 |
Correct |
402 ms |
68696 KB |
Output is correct |
74 |
Correct |
0 ms |
212 KB |
Output is correct |
75 |
Correct |
0 ms |
320 KB |
Output is correct |
76 |
Correct |
0 ms |
212 KB |
Output is correct |
77 |
Correct |
1 ms |
244 KB |
Output is correct |
78 |
Correct |
0 ms |
212 KB |
Output is correct |
79 |
Correct |
4 ms |
964 KB |
Output is correct |
80 |
Correct |
541 ms |
68708 KB |
Output is correct |
81 |
Correct |
572 ms |
68684 KB |
Output is correct |
82 |
Correct |
480 ms |
68620 KB |
Output is correct |
83 |
Correct |
480 ms |
68720 KB |
Output is correct |
84 |
Correct |
488 ms |
68688 KB |
Output is correct |
85 |
Correct |
468 ms |
68608 KB |
Output is correct |
86 |
Correct |
103 ms |
23372 KB |
Output is correct |
87 |
Correct |
0 ms |
212 KB |
Output is correct |