This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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] = ((long long) 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 (stderr)
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);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |