#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, M = 21, MOD = 1e4 + 7;
int n, m, q, a[N], b[N], t[4 * N][M];
inline void upd(int v){
for(int i = 0; i <= m; i++){
t[v][i] = 0;
}
for(int i = 0; i <= m; i++){
for(int j = 0; j <= m; j++){
t[v][min(m, i + j)] += t[v + v][i] * t[v + v + 1][j] % MOD;
}
}
for(int i = 0; i <= m; i++){
t[v][i] %= MOD;
}
}
void build(int v, int l, int r){
if(l == r){
t[v][0] = b[l];
t[v][1] = a[l];
return;
}
int mid = (r + l) >> 1;
build(v + v, l, mid);
build(v + v + 1, mid + 1, r);
upd(v);
}
void update(int v, int l, int r, int pos){
if(l == r){
t[v][0] = b[l];
t[v][1] = a[l];
return;
}
int mid = (r + l) >> 1;
if(pos <= mid){
update(v + v, l, mid, pos);
}
else{
update(v + v + 1, mid + 1, r, pos);
}
upd(v);
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> m;
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);
cin >> q;
while(q--){
int pos, x, y;
cin >> pos >> x >> y;
a[pos] = x;
b[pos] = y;
a[pos] %= MOD;
b[pos] %= MOD;
update(1, 1, n, pos);
cout << t[1][m] << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
512 KB |
Output is correct |
2 |
Correct |
13 ms |
512 KB |
Output is correct |
3 |
Correct |
19 ms |
512 KB |
Output is correct |
4 |
Correct |
318 ms |
14584 KB |
Output is correct |
5 |
Correct |
1143 ms |
26808 KB |
Output is correct |
6 |
Correct |
1283 ms |
26488 KB |
Output is correct |
7 |
Correct |
640 ms |
14864 KB |
Output is correct |
8 |
Correct |
376 ms |
25888 KB |
Output is correct |
9 |
Correct |
619 ms |
26872 KB |
Output is correct |
10 |
Correct |
2059 ms |
26812 KB |
Output is correct |