#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100005;
const int C = 22;
const int mod = 10007;
int n, c;
struct Info {
int d[C];
void upd(int a,int b) {
d[0] = b;
d[1] = a;
}
};
int a[N], b[N];
Info t[N << 2];
void Merge(Info &v, Info lv, Info rv) {
for (int i = 0; i <= c; ++i) {
v.d[i] = 0;
}
for (int i = 0; i <= c; ++i) {
for (int j = 0; j <= c; ++j) {
(v.d[min(i + j, c)] += (ll) (lv.d[i] * rv.d[j])) %= mod;
}
}
}
void build(int v,int l,int r) {
if (l == r) {
t[v].upd(a[l], b[l]);
return;
}
int md = (l + r) >> 1;
build(v << 1, l, md);
build(v << 1 | 1, md + 1, r);
Merge(t[v], t[v << 1], t[v << 1 | 1]);
}
void upd(int v,int l,int r,int p,int a,int b) {
if (l == r) {
t[v].upd(a, b);
return;
}
int md = (l + r) >> 1;
if (p <= md) {
upd(v << 1, l, md, p, a, b);
} else {
upd(v << 1 | 1, md + 1, r, p, a, b);
}
Merge(t[v], t[v << 1], t[v << 1 | 1]);
}
int main() {
ios_base::sync_with_stdio(false);
cin >> n >> c;
for (int i = 1; i <= n; ++i) {
cin >> a[i]; a[i] %= mod;
}
for (int i = 1; i <= n; ++i) {
cin >> b[i]; b[i] %= mod;
}
build(1, 1, n);
int q;
cin >> q;
while (q--) {
int p, ap, bp;
cin >> p >> ap >> bp;
ap %= mod, bp %= mod;
upd(1, 1, n, p, ap, bp);
cout << t[1].d[c] << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
512 KB |
Output is correct |
2 |
Correct |
14 ms |
512 KB |
Output is correct |
3 |
Correct |
33 ms |
512 KB |
Output is correct |
4 |
Correct |
553 ms |
12508 KB |
Output is correct |
5 |
Correct |
1661 ms |
24148 KB |
Output is correct |
6 |
Correct |
2262 ms |
24136 KB |
Output is correct |
7 |
Correct |
1035 ms |
12460 KB |
Output is correct |
8 |
Correct |
587 ms |
23816 KB |
Output is correct |
9 |
Correct |
1129 ms |
24100 KB |
Output is correct |
10 |
Correct |
3526 ms |
24156 KB |
Output is correct |