#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll inf = 4e18;
ll mul(ll a, ll b) {
if (a > (inf / b)) {
return inf;
} else {
return a * b;
}
}
int main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
ll A, B;
cin >> A >> B;
A /= __gcd(A, B + 1);
ll C = mul(A, B);
vector<pair<ll, int>> go;
for (int i = 0; i < n; ++i) {
ll l, r;
cin >> l >> r;
if (r - l + 1 >= C) {
go.emplace_back(0, 1);
go.emplace_back(C, -1);
} else if (l % C <= r % C) {
l %= C, r %= C;
go.emplace_back(l, 1);
go.emplace_back(r + 1, -1);
} else {
l %= C, r %= C;
go.emplace_back(l, 1);
go.emplace_back(C, -1);
go.emplace_back(0, 1);
go.emplace_back(r + 1, -1);
}
}
sort(go.begin(), go.end());
ll ans = 0;
int l = 0;
int cnt = 0;
while (l < go.size()) {
int r = l;
while (r < go.size() && go[r].first == go[l].first) {
cnt += go[r++].second;
}
if (cnt) {
ans += go[r].first - go[l].first;
}
l = r;
}
cout << ans << "\n";
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:47:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while (l < go.size()) {
~~^~~~~~~~~~~
strange_device.cpp:49:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while (r < go.size() && go[r].first == go[l].first) {
~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
10 ms |
1016 KB |
Output is correct |
3 |
Correct |
11 ms |
1000 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
380 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
408 KB |
Output is correct |
10 |
Correct |
2 ms |
252 KB |
Output is correct |
11 |
Correct |
2 ms |
380 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
10 ms |
1016 KB |
Output is correct |
17 |
Correct |
88 ms |
4596 KB |
Output is correct |
18 |
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 |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
256 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 |
544 ms |
33260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
774 ms |
33344 KB |
Output is correct |
3 |
Correct |
810 ms |
33300 KB |
Output is correct |
4 |
Correct |
779 ms |
33352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
774 ms |
33344 KB |
Output is correct |
3 |
Correct |
810 ms |
33300 KB |
Output is correct |
4 |
Correct |
779 ms |
33352 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
799 ms |
33296 KB |
Output is correct |
7 |
Correct |
774 ms |
33300 KB |
Output is correct |
8 |
Correct |
812 ms |
33344 KB |
Output is correct |
9 |
Correct |
928 ms |
33268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
774 ms |
33344 KB |
Output is correct |
3 |
Correct |
810 ms |
33300 KB |
Output is correct |
4 |
Correct |
779 ms |
33352 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
77 ms |
4584 KB |
Output is correct |
7 |
Correct |
80 ms |
4584 KB |
Output is correct |
8 |
Correct |
77 ms |
4604 KB |
Output is correct |
9 |
Correct |
80 ms |
4596 KB |
Output is correct |
10 |
Correct |
64 ms |
4584 KB |
Output is correct |
11 |
Correct |
77 ms |
4684 KB |
Output is correct |
12 |
Correct |
85 ms |
4628 KB |
Output is correct |
13 |
Correct |
86 ms |
4580 KB |
Output is correct |
14 |
Correct |
75 ms |
4584 KB |
Output is correct |
15 |
Correct |
91 ms |
4556 KB |
Output is correct |
16 |
Correct |
112 ms |
4580 KB |
Output is correct |
17 |
Correct |
80 ms |
4536 KB |
Output is correct |
18 |
Correct |
803 ms |
33336 KB |
Output is correct |
19 |
Correct |
757 ms |
33316 KB |
Output is correct |
20 |
Correct |
923 ms |
33344 KB |
Output is correct |
21 |
Correct |
88 ms |
4708 KB |
Output is correct |
22 |
Correct |
70 ms |
4584 KB |
Output is correct |
23 |
Correct |
225 ms |
16932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
84 ms |
4560 KB |
Output is correct |
3 |
Correct |
95 ms |
4712 KB |
Output is correct |
4 |
Correct |
994 ms |
33420 KB |
Output is correct |
5 |
Correct |
86 ms |
4588 KB |
Output is correct |
6 |
Correct |
85 ms |
4608 KB |
Output is correct |
7 |
Correct |
85 ms |
4584 KB |
Output is correct |
8 |
Correct |
91 ms |
4556 KB |
Output is correct |
9 |
Correct |
95 ms |
4556 KB |
Output is correct |
10 |
Correct |
90 ms |
4556 KB |
Output is correct |
11 |
Correct |
88 ms |
4584 KB |
Output is correct |
12 |
Correct |
78 ms |
4584 KB |
Output is correct |
13 |
Correct |
89 ms |
4556 KB |
Output is correct |
14 |
Correct |
904 ms |
33344 KB |
Output is correct |
15 |
Correct |
89 ms |
4584 KB |
Output is correct |
16 |
Correct |
746 ms |
33452 KB |
Output is correct |
17 |
Correct |
791 ms |
33328 KB |
Output is correct |
18 |
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 |
10 ms |
1016 KB |
Output is correct |
3 |
Correct |
11 ms |
1000 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
380 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
408 KB |
Output is correct |
10 |
Correct |
2 ms |
252 KB |
Output is correct |
11 |
Correct |
2 ms |
380 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
10 ms |
1016 KB |
Output is correct |
17 |
Correct |
88 ms |
4596 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
504 KB |
Output is correct |
21 |
Correct |
2 ms |
256 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
256 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 |
544 ms |
33260 KB |
Output is correct |
29 |
Correct |
2 ms |
376 KB |
Output is correct |
30 |
Correct |
774 ms |
33344 KB |
Output is correct |
31 |
Correct |
810 ms |
33300 KB |
Output is correct |
32 |
Correct |
779 ms |
33352 KB |
Output is correct |
33 |
Correct |
2 ms |
376 KB |
Output is correct |
34 |
Correct |
799 ms |
33296 KB |
Output is correct |
35 |
Correct |
774 ms |
33300 KB |
Output is correct |
36 |
Correct |
812 ms |
33344 KB |
Output is correct |
37 |
Correct |
928 ms |
33268 KB |
Output is correct |
38 |
Correct |
2 ms |
376 KB |
Output is correct |
39 |
Correct |
77 ms |
4584 KB |
Output is correct |
40 |
Correct |
80 ms |
4584 KB |
Output is correct |
41 |
Correct |
77 ms |
4604 KB |
Output is correct |
42 |
Correct |
80 ms |
4596 KB |
Output is correct |
43 |
Correct |
64 ms |
4584 KB |
Output is correct |
44 |
Correct |
77 ms |
4684 KB |
Output is correct |
45 |
Correct |
85 ms |
4628 KB |
Output is correct |
46 |
Correct |
86 ms |
4580 KB |
Output is correct |
47 |
Correct |
75 ms |
4584 KB |
Output is correct |
48 |
Correct |
91 ms |
4556 KB |
Output is correct |
49 |
Correct |
112 ms |
4580 KB |
Output is correct |
50 |
Correct |
80 ms |
4536 KB |
Output is correct |
51 |
Correct |
803 ms |
33336 KB |
Output is correct |
52 |
Correct |
757 ms |
33316 KB |
Output is correct |
53 |
Correct |
923 ms |
33344 KB |
Output is correct |
54 |
Correct |
88 ms |
4708 KB |
Output is correct |
55 |
Correct |
70 ms |
4584 KB |
Output is correct |
56 |
Correct |
225 ms |
16932 KB |
Output is correct |
57 |
Correct |
2 ms |
256 KB |
Output is correct |
58 |
Correct |
84 ms |
4560 KB |
Output is correct |
59 |
Correct |
95 ms |
4712 KB |
Output is correct |
60 |
Correct |
994 ms |
33420 KB |
Output is correct |
61 |
Correct |
86 ms |
4588 KB |
Output is correct |
62 |
Correct |
85 ms |
4608 KB |
Output is correct |
63 |
Correct |
85 ms |
4584 KB |
Output is correct |
64 |
Correct |
91 ms |
4556 KB |
Output is correct |
65 |
Correct |
95 ms |
4556 KB |
Output is correct |
66 |
Correct |
90 ms |
4556 KB |
Output is correct |
67 |
Correct |
88 ms |
4584 KB |
Output is correct |
68 |
Correct |
78 ms |
4584 KB |
Output is correct |
69 |
Correct |
89 ms |
4556 KB |
Output is correct |
70 |
Correct |
904 ms |
33344 KB |
Output is correct |
71 |
Correct |
89 ms |
4584 KB |
Output is correct |
72 |
Correct |
746 ms |
33452 KB |
Output is correct |
73 |
Correct |
791 ms |
33328 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 |
376 KB |
Output is correct |
78 |
Correct |
2 ms |
348 KB |
Output is correct |
79 |
Correct |
9 ms |
1016 KB |
Output is correct |
80 |
Correct |
965 ms |
33248 KB |
Output is correct |
81 |
Correct |
998 ms |
33368 KB |
Output is correct |
82 |
Correct |
886 ms |
33336 KB |
Output is correct |
83 |
Correct |
896 ms |
33324 KB |
Output is correct |
84 |
Correct |
902 ms |
33344 KB |
Output is correct |
85 |
Correct |
904 ms |
33328 KB |
Output is correct |
86 |
Correct |
220 ms |
16836 KB |
Output is correct |
87 |
Correct |
2 ms |
376 KB |
Output is correct |