# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
393024 | rainboy | Relativnost (COCI15_relativnost) | C11 | 2516 ms | 22804 KiB |
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>
#include <string.h>
#define N 100000
#define N_ (1 << 17) /* N_ = pow2(ceil(log2(N))) */
#define K 20
#define MD 10007
int min(int a, int b) { return a < b ? a : b; }
int st[N_ * 2][K + 1], n_, k;
void pul(int i) {
int l = i << 1, r = l | 1, a, b;
memset(st[i], 0, (k + 1) * sizeof *st[i]);
for (a = 0; a <= k; a++) {
int x = st[l][a];
if (x == 0)
continue;
for (b = 0; b <= k; b++) {
int y = st[r][b], c = min(a + b, k);
if (y == 0)
continue;
st[i][c] = (st[i][c] + x * y) % MD;
}
}
}
void build(int *aa, int *bb, int n) {
int i;
n_ = 1;
while (n_ < n)
n_ <<= 1;
for (i = 0; i < n; i++)
st[n_ + i][0] = bb[i] % MD, st[n_ + i][1] = aa[i] % MD;
for (i = n_ - 1; i > 0; i--)
pul(i);
}
void update(int i, int a, int b) {
i += n_;
st[i][0] = b % MD, st[i][1] = a % MD;
while (i > 1)
pul(i >>= 1);
}
int main() {
static int aa[N], bb[N];
int n, q, i;
scanf("%d%d", &n, &k);
for (i = 0; i < n; i++)
scanf("%d", &aa[i]);
for (i = 0; i < n; i++)
scanf("%d", &bb[i]);
build(aa, bb, n);
scanf("%d", &q);
while (q--) {
int a, b;
scanf("%d%d%d", &i, &a, &b), i--;
update(i, a, b);
printf("%d\n", st[1][k]);
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |