#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, M = 25, MOD = 1e4 + 7;
int n, m, q, a[N], b[N];
struct item{
int dp[M];
item(){
memset(dp, 0, sizeof(dp));
}
};
item t[4 * N];
inline item mrg(item a, item b){
item c;
for(int i = 0; i <= m; i++){
for(int j = 0; j <= m; j++){
c.dp[min(m, i + j)] += 1LL * a.dp[i] * b.dp[j] % MOD;
}
}
for(int i = 0; i <= m; i++){
c.dp[i] %= MOD;
}
return c;
}
void build(int v, int l, int r){
if(l == r){
t[v].dp[0] = b[l];
t[v].dp[1] = a[l];
return;
}
int mid = (r + l) >> 1;
build(v + v, l, mid);
build(v + v + 1, mid + 1, r);
t[v] = mrg(t[v + v], t[v + v + 1]);
}
void update(int v, int l, int r, int pos){
if(l == r){
t[v].dp[0] = b[l];
t[v].dp[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);
}
t[v] = mrg(t[v + v], t[v + v + 1]);
}
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].dp[m] << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
48 ms |
33792 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Runtime error |
40 ms |
33792 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
3 |
Runtime error |
40 ms |
33792 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
4 |
Runtime error |
38 ms |
33792 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
5 |
Runtime error |
38 ms |
33792 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
6 |
Runtime error |
42 ms |
33792 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
7 |
Runtime error |
36 ms |
33792 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
8 |
Runtime error |
39 ms |
33792 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
9 |
Runtime error |
37 ms |
33792 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
10 |
Runtime error |
43 ms |
33792 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |