#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 4e6;
int n, m, tot, sum[maxn + 3];
ll A, B, C, l, r, temp[maxn + 3];
pair<ll, ll> sect[maxn + 3];
ll gcd(ll a, ll b) {
return b ? gcd(b, a % b) : a;
}
int main() {
scanf("%d %lld %lld", &n, &A, &B);
C = A / gcd(A, B + 1) * B;
for (int i = 1; i <= n; i++) {
scanf("%lld %lld", &l, &r);
if (r - l + 1 >= C) {
printf("%lld\n", C);
return 0;
}
l %= C, r %= C;
if (l <= r) {
sect[++tot] = make_pair(l, r);
} else {
sect[++tot] = make_pair(0, r);
sect[++tot] = make_pair(l, C - 1);
}
}
for (int i = 1; i <= tot; i++) {
temp[++m] = sect[i].first;
temp[++m] = sect[i].second + 1;
}
sort(temp + 1, temp + m + 1);
for (int i = 1; i <= tot; i++) {
int x = lower_bound(temp + 1, temp + m + 1, sect[i].first) - temp;
int y = lower_bound(temp + 1, temp + m + 1, sect[i].second + 1) - temp;
sum[x]++, sum[y]--;
}
ll ans = 0;
for (int i = 1; i <= m; i++) {
sum[i] += sum[i - 1];
if (sum[i]) {
ans += temp[i + 1] - temp[i];
}
}
printf("%lld\n", ans);
return 0;
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:12:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
12 | scanf("%d %lld %lld", &n, &A, &B);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:15:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
15 | scanf("%lld %lld", &l, &r);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
7 ms |
748 KB |
Output is correct |
3 |
Correct |
7 ms |
768 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
0 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
10 ms |
748 KB |
Output is correct |
17 |
Correct |
77 ms |
4204 KB |
Output is correct |
18 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
450 ms |
39644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
721 ms |
39532 KB |
Output is correct |
3 |
Correct |
749 ms |
76652 KB |
Output is correct |
4 |
Correct |
709 ms |
76780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
721 ms |
39532 KB |
Output is correct |
3 |
Correct |
749 ms |
76652 KB |
Output is correct |
4 |
Correct |
709 ms |
76780 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
729 ms |
76652 KB |
Output is correct |
7 |
Correct |
725 ms |
76652 KB |
Output is correct |
8 |
Correct |
733 ms |
76908 KB |
Output is correct |
9 |
Correct |
792 ms |
76652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
721 ms |
39532 KB |
Output is correct |
3 |
Correct |
749 ms |
76652 KB |
Output is correct |
4 |
Correct |
709 ms |
76780 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
71 ms |
8044 KB |
Output is correct |
7 |
Correct |
74 ms |
8044 KB |
Output is correct |
8 |
Correct |
68 ms |
8044 KB |
Output is correct |
9 |
Correct |
71 ms |
8044 KB |
Output is correct |
10 |
Correct |
67 ms |
8044 KB |
Output is correct |
11 |
Correct |
71 ms |
8064 KB |
Output is correct |
12 |
Correct |
70 ms |
8044 KB |
Output is correct |
13 |
Correct |
76 ms |
8064 KB |
Output is correct |
14 |
Correct |
68 ms |
8044 KB |
Output is correct |
15 |
Correct |
79 ms |
8044 KB |
Output is correct |
16 |
Correct |
78 ms |
8044 KB |
Output is correct |
17 |
Correct |
70 ms |
8044 KB |
Output is correct |
18 |
Correct |
724 ms |
61932 KB |
Output is correct |
19 |
Correct |
708 ms |
76780 KB |
Output is correct |
20 |
Correct |
814 ms |
76852 KB |
Output is correct |
21 |
Correct |
80 ms |
8044 KB |
Output is correct |
22 |
Correct |
67 ms |
8044 KB |
Output is correct |
23 |
Correct |
185 ms |
26348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
76 ms |
7916 KB |
Output is correct |
3 |
Correct |
77 ms |
8044 KB |
Output is correct |
4 |
Correct |
831 ms |
76652 KB |
Output is correct |
5 |
Correct |
79 ms |
8044 KB |
Output is correct |
6 |
Correct |
78 ms |
8044 KB |
Output is correct |
7 |
Correct |
76 ms |
8044 KB |
Output is correct |
8 |
Correct |
79 ms |
8044 KB |
Output is correct |
9 |
Correct |
75 ms |
8044 KB |
Output is correct |
10 |
Correct |
78 ms |
8044 KB |
Output is correct |
11 |
Correct |
79 ms |
8044 KB |
Output is correct |
12 |
Correct |
73 ms |
8024 KB |
Output is correct |
13 |
Correct |
78 ms |
8044 KB |
Output is correct |
14 |
Correct |
803 ms |
76628 KB |
Output is correct |
15 |
Correct |
84 ms |
8044 KB |
Output is correct |
16 |
Correct |
703 ms |
76724 KB |
Output is correct |
17 |
Correct |
759 ms |
76712 KB |
Output is correct |
18 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
7 ms |
748 KB |
Output is correct |
3 |
Correct |
7 ms |
768 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
0 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
10 ms |
748 KB |
Output is correct |
17 |
Correct |
77 ms |
4204 KB |
Output is correct |
18 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |