#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100100;
const int C = 22;
const int md = 10007;
int n, c, a[N], b[N], st[4 * N][C];
int mult(int x, int y) { return (x * y) % md; }
void SUM(int &x, int y){
x += y;
if (x >= md)
x -= md;
}
void clear(int v){
for (int i = 0; i <= c; i++)
st[v][i] = 0;
}
void combine(int v, int l, int r){
clear(v);
for (int i = 0; i <= c; i++)
for (int j = 0; j <= c; j++)
SUM(st[v][min(i + j, c)], mult(st[l][i], st[r][j]));
}
void build(int v, int l, int r){
if (l == r){
clear(v);
st[v][0] = b[l] % md;
st[v][1] = a[l] % md;
return;
}
int md = (l + r) >> 1;
build(v + v, l, md);
build(v + v + 1, md + 1, r);
combine(v, v + v, v + v + 1);
}
void update(int v, int l, int r, int ps){
if (l == r){
clear(v);
st[v][0] = b[l] % md;
st[v][1] = a[l] % md;
return;
}
int md = (l + r) >> 1;
if (ps <= md)
update(v + v, l, md, ps);
else update(v + v + 1, md + 1, r, ps);
combine(v, v + v, v + v + 1);
}
int main() {
#ifdef _LOCAL
freopen("in.txt","r",stdin); // freopen("output.txt","w",stdout);
#else
// freopen("mining.in","r",stdin); freopen("mining.out","w",stdout);
ios_base::sync_with_stdio(0); cin.tie(0);
#endif
cin >> n >> c;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= n; i++)
cin >> b[i];
build(1, 1, n);
int qq; cin >> qq;
for (; qq; qq--){
int ps, an, bn; cin >> ps >> an >> bn;
a[ps] = an;
b[ps] = bn;
update(1, 1, n, ps);
cout << st[1][c] << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
512 KB |
Output is correct |
2 |
Correct |
11 ms |
512 KB |
Output is correct |
3 |
Correct |
19 ms |
512 KB |
Output is correct |
4 |
Correct |
372 ms |
12540 KB |
Output is correct |
5 |
Correct |
1181 ms |
24104 KB |
Output is correct |
6 |
Correct |
1728 ms |
24268 KB |
Output is correct |
7 |
Correct |
756 ms |
12408 KB |
Output is correct |
8 |
Correct |
409 ms |
23800 KB |
Output is correct |
9 |
Correct |
731 ms |
23928 KB |
Output is correct |
10 |
Correct |
2754 ms |
24264 KB |
Output is correct |