#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN=100005;
int n,c;
int a[MAXN], b[MAXN];
int T[2*MAXN][21];
const int mod = 10007;
void update(int x){
for (int i=0; i<=c; i++) T[x][i]=0;
for (int i=0; i<=c; i++){
for (int j=0; j<=c; j++){
(T[x][min(c,i+j)]+=(T[2*x][i]*T[2*x+1][j])%mod)%=mod;
}
}
}
void change(int x){
x+=n;
memset(T[x], 0, sizeof T[x]);
T[x][0]=b[x-n]%mod, T[x][1]=a[x-n]%mod;
for (x/=2; x>0; x/=2) {
update(x);
}
}
signed main(){
cin>>n>>c;
for (int i=0; i<n; i++) cin>>a[i];
for (int i=0; i<n; i++) cin>>b[i];
for (int i=0; i<n; i++){
T[i+n][0]=b[i]%mod;
T[i+n][1]=a[i]%mod;
}
for (int i=n-1; i>=0; i--){
update(i);
}
int q; cin>>q;
while(q--){
int p; cin>>p;
p--;
cin>>a[p]>>b[p];
change(p);
cout<<T[1][c]<<'\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
4700 KB |
Output is correct |
2 |
Correct |
12 ms |
4744 KB |
Output is correct |
3 |
Correct |
22 ms |
4700 KB |
Output is correct |
4 |
Correct |
454 ms |
24628 KB |
Output is correct |
5 |
Runtime error |
1209 ms |
36468 KB |
Memory limit exceeded |
6 |
Runtime error |
1733 ms |
38228 KB |
Memory limit exceeded |
7 |
Correct |
733 ms |
28920 KB |
Output is correct |
8 |
Runtime error |
494 ms |
37844 KB |
Memory limit exceeded |
9 |
Correct |
818 ms |
32604 KB |
Output is correct |
10 |
Correct |
2738 ms |
32344 KB |
Output is correct |