#include <stdio.h>
#define N 1000000
long long gcd(long long a, long long b) {
return b == 0 ? a : gcd(b, a % b);
}
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
long long xx[N], yy[N];
void sort(int *ii, int l, int r) {
while (l < r) {
int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp;
while (j < k) {
long long c = xx[ii[j]] != xx[i_] ? xx[ii[j]] - xx[i_] : yy[ii[j]] - yy[i_];
if (c == 0)
j++;
else if (c < 0) {
tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
i++, j++;
} else {
k--;
tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;
}
}
sort(ii, l, i);
l = k;
}
}
int main() {
static int ii[N];
int n, n_, i, ans;
long long a, b;
scanf("%d%lld%lld", &n, &a, &b);
if (n == 1) {
long long l, r, k;
scanf("%lld%lld", &l, &r);
k = a / gcd(a, b + 1);
printf("%lld\n", k <= (r - l + 1) / b ? k * b : r - l + 1);
return 0;
}
n_ = 0;
while (n--) {
long long l, r;
scanf("%lld%lld", &l, &r);
while (l <= r) {
xx[n_] = (l + l / b) % a, yy[n_] = l % b, n_++;
l++;
}
}
n = n_;
for (i = 0; i < n; i++)
ii[i] = i;
sort(ii, 0, n);
ans = 1;
for (i = 1; i < n; i++)
if (xx[ii[i]] != xx[ii[i - 1]] || yy[ii[i]] != yy[ii[i - 1]])
ans++;
printf("%d\n", ans);
return 0;
}
Compilation message
strange_device.c: In function 'main':
strange_device.c:44:2: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
44 | scanf("%d%lld%lld", &n, &a, &b);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.c:48:3: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
48 | scanf("%lld%lld", &l, &r);
| ^~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.c:57:3: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
57 | scanf("%lld%lld", &l, &r);
| ^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
48 ms |
4076 KB |
Output is correct |
3 |
Correct |
73 ms |
5952 KB |
Output is correct |
4 |
Correct |
3 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
11 ms |
1536 KB |
Output is correct |
10 |
Correct |
1 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 |
69 ms |
6252 KB |
Output is correct |
16 |
Correct |
27 ms |
2412 KB |
Output is correct |
17 |
Correct |
59 ms |
2284 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is 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 |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
129 ms |
13036 KB |
Output is correct |
3 |
Correct |
185 ms |
12780 KB |
Output is correct |
4 |
Correct |
163 ms |
12524 KB |
Output is correct |
5 |
Runtime error |
42 ms |
32364 KB |
Execution killed with signal 11 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Runtime error |
546 ms |
40044 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Runtime error |
546 ms |
40044 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Runtime error |
546 ms |
40044 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Runtime error |
57 ms |
32108 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
48 ms |
4076 KB |
Output is correct |
3 |
Correct |
73 ms |
5952 KB |
Output is correct |
4 |
Correct |
3 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
11 ms |
1536 KB |
Output is correct |
10 |
Correct |
1 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 |
69 ms |
6252 KB |
Output is correct |
16 |
Correct |
27 ms |
2412 KB |
Output is correct |
17 |
Correct |
59 ms |
2284 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
129 ms |
13036 KB |
Output is correct |
26 |
Correct |
185 ms |
12780 KB |
Output is correct |
27 |
Correct |
163 ms |
12524 KB |
Output is correct |
28 |
Runtime error |
42 ms |
32364 KB |
Execution killed with signal 11 |