#include <stdio.h>
#define N 500000
#define K 32 /* K = ceil(log2(2 * 10^9)) + 1 */
int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }
int main() {
static int aa[N + 1], ii[K];
int n, q, k, h, i, j;
scanf("%d%d", &n, &q);
aa[0] = 1;
for (i = 1; i <= n; i++)
scanf("%d", &aa[i]);
for (i = 1; i <= n; i++)
aa[i] = (aa[i] + aa[i - 1] - 1) / aa[i - 1] * aa[i - 1];
k = 0;
for (i = 0; i <= n; i++)
if (i == 0 || aa[i] != aa[i - 1])
ii[k++] = i;
while (q--) {
int t, l, r, x, ans;
scanf("%d%d%d", &t, &l, &r);
ans = 0;
for (h = 0; h < k; h++) {
i = ii[h], j = h + 1 == k ? n : ii[h + 1] - 1, x = t / aa[i] * aa[i];
ans += max(min(x - i, r) - max(x - j, l) + 1, 0);
}
printf("%d\n", ans);
}
return 0;
}
Compilation message
worst_reporter3.c: In function 'main':
worst_reporter3.c:13:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | scanf("%d%d", &n, &q);
| ^~~~~~~~~~~~~~~~~~~~~
worst_reporter3.c:16:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
16 | scanf("%d", &aa[i]);
| ^~~~~~~~~~~~~~~~~~~
worst_reporter3.c:26:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
26 | scanf("%d%d%d", &t, &l, &r);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
238 ms |
5312 KB |
Output is correct |
2 |
Correct |
263 ms |
20636 KB |
Output is correct |
3 |
Correct |
260 ms |
20572 KB |
Output is correct |
4 |
Correct |
265 ms |
20676 KB |
Output is correct |
5 |
Correct |
257 ms |
20700 KB |
Output is correct |
6 |
Correct |
251 ms |
20596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
238 ms |
5312 KB |
Output is correct |
2 |
Correct |
263 ms |
20636 KB |
Output is correct |
3 |
Correct |
260 ms |
20572 KB |
Output is correct |
4 |
Correct |
265 ms |
20676 KB |
Output is correct |
5 |
Correct |
257 ms |
20700 KB |
Output is correct |
6 |
Correct |
251 ms |
20596 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Runtime error |
68 ms |
9248 KB |
Execution killed with signal 8 |
14 |
Halted |
0 ms |
0 KB |
- |