#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define s second
#define f first
typedef long long ll;
const ll MOD = 1e9+9;
const ll LOGN = 20;
const ll MAXN = 6 * 1e6 + 50;
vector<pair<ll,ll>> v;
vector<ll> cc;
ll calc(ll A, ll B) {
return 1e18 / A < B ? 1e18 : A / __gcd(A, B + 1) * B;
if (1e18 / A < B)
return 1e18;
if (1e18 / B < A)
return 1e18;
return A * B;
}
int index(ll k) {
return upper_bound(cc.begin(), cc.end(), k) - cc.begin();
}
ll cnt[MAXN];
int main() {
fast
ll n, A, B;
cin >> n >> A >> B;
ll period = calc(A, B);
for (int i = 1; i <= n; i++) {
ll l, r;
cin >> l >> r;
ll left_mod = l % period;
ll right_mod = r % period;
if (r - l + 1 > period - left_mod) {
v.push_back({left_mod, period - 1});
v.push_back({0, right_mod});
} else
v.push_back({left_mod, right_mod});
}
for (auto u : v) {
cc.push_back(u.f);
cc.push_back(u.s);
cc.push_back(u.s+1);
}
sort(cc.begin(), cc.end());
cc.erase(unique(cc.begin(), cc.end()), cc.end());
for (auto u : v) {
cnt[index(u.f)]++;
cnt[index(u.s + 1)]--;
}
for (int i = 1; i < MAXN; i++)
cnt[i] += cnt[i-1];
ll ans = 0;
for (int i = 0; i < cc.size() - 1; i++) {
if (cnt[i+1]) {
ans += cc[i+1] - cc[i];
}
}
cout << ans << "\n";
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:62:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | for (int i = 0; i < cc.size() - 1; i++) {
| ~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
47184 KB |
Output is correct |
2 |
Correct |
24 ms |
48204 KB |
Output is correct |
3 |
Correct |
24 ms |
48204 KB |
Output is correct |
4 |
Correct |
18 ms |
47312 KB |
Output is correct |
5 |
Correct |
18 ms |
47196 KB |
Output is correct |
6 |
Correct |
18 ms |
47316 KB |
Output is correct |
7 |
Correct |
18 ms |
47188 KB |
Output is correct |
8 |
Correct |
18 ms |
47192 KB |
Output is correct |
9 |
Correct |
18 ms |
47196 KB |
Output is correct |
10 |
Correct |
18 ms |
47196 KB |
Output is correct |
11 |
Correct |
18 ms |
47192 KB |
Output is correct |
12 |
Correct |
18 ms |
47196 KB |
Output is correct |
13 |
Correct |
18 ms |
47188 KB |
Output is correct |
14 |
Correct |
19 ms |
47196 KB |
Output is correct |
15 |
Correct |
18 ms |
47308 KB |
Output is correct |
16 |
Correct |
23 ms |
48220 KB |
Output is correct |
17 |
Correct |
85 ms |
56644 KB |
Output is correct |
18 |
Correct |
19 ms |
47280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
47192 KB |
Output is correct |
2 |
Correct |
18 ms |
47192 KB |
Output is correct |
3 |
Correct |
18 ms |
47196 KB |
Output is correct |
4 |
Correct |
18 ms |
47196 KB |
Output is correct |
5 |
Correct |
18 ms |
47188 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
47256 KB |
Output is correct |
2 |
Correct |
19 ms |
47444 KB |
Output is correct |
3 |
Correct |
21 ms |
47316 KB |
Output is correct |
4 |
Correct |
19 ms |
47396 KB |
Output is correct |
5 |
Correct |
274 ms |
100684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
47196 KB |
Output is correct |
2 |
Correct |
556 ms |
105508 KB |
Output is correct |
3 |
Correct |
602 ms |
106788 KB |
Output is correct |
4 |
Correct |
576 ms |
125292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
47196 KB |
Output is correct |
2 |
Correct |
556 ms |
105508 KB |
Output is correct |
3 |
Correct |
602 ms |
106788 KB |
Output is correct |
4 |
Correct |
576 ms |
125292 KB |
Output is correct |
5 |
Correct |
20 ms |
47196 KB |
Output is correct |
6 |
Correct |
620 ms |
124476 KB |
Output is correct |
7 |
Correct |
554 ms |
125120 KB |
Output is correct |
8 |
Correct |
595 ms |
125188 KB |
Output is correct |
9 |
Correct |
689 ms |
125104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
47196 KB |
Output is correct |
2 |
Correct |
556 ms |
105508 KB |
Output is correct |
3 |
Correct |
602 ms |
106788 KB |
Output is correct |
4 |
Correct |
576 ms |
125292 KB |
Output is correct |
5 |
Correct |
19 ms |
47192 KB |
Output is correct |
6 |
Correct |
79 ms |
55448 KB |
Output is correct |
7 |
Correct |
79 ms |
56488 KB |
Output is correct |
8 |
Correct |
78 ms |
55012 KB |
Output is correct |
9 |
Correct |
77 ms |
55732 KB |
Output is correct |
10 |
Correct |
69 ms |
55360 KB |
Output is correct |
11 |
Correct |
73 ms |
55412 KB |
Output is correct |
12 |
Correct |
70 ms |
55780 KB |
Output is correct |
13 |
Correct |
92 ms |
55416 KB |
Output is correct |
14 |
Correct |
68 ms |
56412 KB |
Output is correct |
15 |
Correct |
91 ms |
55940 KB |
Output is correct |
16 |
Correct |
84 ms |
56488 KB |
Output is correct |
17 |
Correct |
72 ms |
56136 KB |
Output is correct |
18 |
Correct |
645 ms |
125496 KB |
Output is correct |
19 |
Correct |
574 ms |
125164 KB |
Output is correct |
20 |
Correct |
699 ms |
124328 KB |
Output is correct |
21 |
Correct |
93 ms |
55136 KB |
Output is correct |
22 |
Correct |
64 ms |
55452 KB |
Output is correct |
23 |
Correct |
140 ms |
74916 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
47188 KB |
Output is correct |
2 |
Correct |
78 ms |
54264 KB |
Output is correct |
3 |
Correct |
79 ms |
53768 KB |
Output is correct |
4 |
Correct |
743 ms |
105464 KB |
Output is correct |
5 |
Correct |
83 ms |
54616 KB |
Output is correct |
6 |
Correct |
79 ms |
53400 KB |
Output is correct |
7 |
Correct |
81 ms |
54264 KB |
Output is correct |
8 |
Correct |
84 ms |
53828 KB |
Output is correct |
9 |
Correct |
77 ms |
54056 KB |
Output is correct |
10 |
Correct |
81 ms |
53780 KB |
Output is correct |
11 |
Correct |
96 ms |
53988 KB |
Output is correct |
12 |
Correct |
71 ms |
54588 KB |
Output is correct |
13 |
Correct |
86 ms |
55156 KB |
Output is correct |
14 |
Correct |
678 ms |
106564 KB |
Output is correct |
15 |
Correct |
84 ms |
54336 KB |
Output is correct |
16 |
Correct |
606 ms |
124648 KB |
Output is correct |
17 |
Correct |
671 ms |
124500 KB |
Output is correct |
18 |
Correct |
19 ms |
47196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
47184 KB |
Output is correct |
2 |
Correct |
24 ms |
48204 KB |
Output is correct |
3 |
Correct |
24 ms |
48204 KB |
Output is correct |
4 |
Correct |
18 ms |
47312 KB |
Output is correct |
5 |
Correct |
18 ms |
47196 KB |
Output is correct |
6 |
Correct |
18 ms |
47316 KB |
Output is correct |
7 |
Correct |
18 ms |
47188 KB |
Output is correct |
8 |
Correct |
18 ms |
47192 KB |
Output is correct |
9 |
Correct |
18 ms |
47196 KB |
Output is correct |
10 |
Correct |
18 ms |
47196 KB |
Output is correct |
11 |
Correct |
18 ms |
47192 KB |
Output is correct |
12 |
Correct |
18 ms |
47196 KB |
Output is correct |
13 |
Correct |
18 ms |
47188 KB |
Output is correct |
14 |
Correct |
19 ms |
47196 KB |
Output is correct |
15 |
Correct |
18 ms |
47308 KB |
Output is correct |
16 |
Correct |
23 ms |
48220 KB |
Output is correct |
17 |
Correct |
85 ms |
56644 KB |
Output is correct |
18 |
Correct |
19 ms |
47280 KB |
Output is correct |
19 |
Correct |
19 ms |
47192 KB |
Output is correct |
20 |
Correct |
18 ms |
47192 KB |
Output is correct |
21 |
Correct |
18 ms |
47196 KB |
Output is correct |
22 |
Correct |
18 ms |
47196 KB |
Output is correct |
23 |
Correct |
18 ms |
47188 KB |
Output is correct |
24 |
Correct |
20 ms |
47256 KB |
Output is correct |
25 |
Correct |
19 ms |
47444 KB |
Output is correct |
26 |
Correct |
21 ms |
47316 KB |
Output is correct |
27 |
Correct |
19 ms |
47396 KB |
Output is correct |
28 |
Correct |
274 ms |
100684 KB |
Output is correct |
29 |
Correct |
20 ms |
47196 KB |
Output is correct |
30 |
Correct |
556 ms |
105508 KB |
Output is correct |
31 |
Correct |
602 ms |
106788 KB |
Output is correct |
32 |
Correct |
576 ms |
125292 KB |
Output is correct |
33 |
Correct |
20 ms |
47196 KB |
Output is correct |
34 |
Correct |
620 ms |
124476 KB |
Output is correct |
35 |
Correct |
554 ms |
125120 KB |
Output is correct |
36 |
Correct |
595 ms |
125188 KB |
Output is correct |
37 |
Correct |
689 ms |
125104 KB |
Output is correct |
38 |
Correct |
19 ms |
47192 KB |
Output is correct |
39 |
Correct |
79 ms |
55448 KB |
Output is correct |
40 |
Correct |
79 ms |
56488 KB |
Output is correct |
41 |
Correct |
78 ms |
55012 KB |
Output is correct |
42 |
Correct |
77 ms |
55732 KB |
Output is correct |
43 |
Correct |
69 ms |
55360 KB |
Output is correct |
44 |
Correct |
73 ms |
55412 KB |
Output is correct |
45 |
Correct |
70 ms |
55780 KB |
Output is correct |
46 |
Correct |
92 ms |
55416 KB |
Output is correct |
47 |
Correct |
68 ms |
56412 KB |
Output is correct |
48 |
Correct |
91 ms |
55940 KB |
Output is correct |
49 |
Correct |
84 ms |
56488 KB |
Output is correct |
50 |
Correct |
72 ms |
56136 KB |
Output is correct |
51 |
Correct |
645 ms |
125496 KB |
Output is correct |
52 |
Correct |
574 ms |
125164 KB |
Output is correct |
53 |
Correct |
699 ms |
124328 KB |
Output is correct |
54 |
Correct |
93 ms |
55136 KB |
Output is correct |
55 |
Correct |
64 ms |
55452 KB |
Output is correct |
56 |
Correct |
140 ms |
74916 KB |
Output is correct |
57 |
Correct |
18 ms |
47188 KB |
Output is correct |
58 |
Correct |
78 ms |
54264 KB |
Output is correct |
59 |
Correct |
79 ms |
53768 KB |
Output is correct |
60 |
Correct |
743 ms |
105464 KB |
Output is correct |
61 |
Correct |
83 ms |
54616 KB |
Output is correct |
62 |
Correct |
79 ms |
53400 KB |
Output is correct |
63 |
Correct |
81 ms |
54264 KB |
Output is correct |
64 |
Correct |
84 ms |
53828 KB |
Output is correct |
65 |
Correct |
77 ms |
54056 KB |
Output is correct |
66 |
Correct |
81 ms |
53780 KB |
Output is correct |
67 |
Correct |
96 ms |
53988 KB |
Output is correct |
68 |
Correct |
71 ms |
54588 KB |
Output is correct |
69 |
Correct |
86 ms |
55156 KB |
Output is correct |
70 |
Correct |
678 ms |
106564 KB |
Output is correct |
71 |
Correct |
84 ms |
54336 KB |
Output is correct |
72 |
Correct |
606 ms |
124648 KB |
Output is correct |
73 |
Correct |
671 ms |
124500 KB |
Output is correct |
74 |
Correct |
19 ms |
47196 KB |
Output is correct |
75 |
Correct |
19 ms |
47192 KB |
Output is correct |
76 |
Correct |
18 ms |
47288 KB |
Output is correct |
77 |
Correct |
19 ms |
47448 KB |
Output is correct |
78 |
Correct |
24 ms |
47188 KB |
Output is correct |
79 |
Correct |
25 ms |
48216 KB |
Output is correct |
80 |
Correct |
740 ms |
123932 KB |
Output is correct |
81 |
Correct |
719 ms |
125204 KB |
Output is correct |
82 |
Correct |
689 ms |
123932 KB |
Output is correct |
83 |
Correct |
697 ms |
125084 KB |
Output is correct |
84 |
Correct |
670 ms |
125464 KB |
Output is correct |
85 |
Correct |
680 ms |
124112 KB |
Output is correct |
86 |
Correct |
151 ms |
73256 KB |
Output is correct |
87 |
Correct |
31 ms |
47188 KB |
Output is correct |