#include <bits/stdc++.h>
#define mod 10007
using namespace std;
int n,m,Q,a[100010],b[100010],t[800100][22],sum;
void update(int v){
for(int k=0;k<=m;k++)
t[v][k]=0;
for(int i=0;i<=m;++i)
for(int j=0;j<=m;++j){
t[v][min(i+j,m)]+=((t[v*2][i])*(t[v*2+1][j]))%mod;
}
for(int k=0;k<=m;k++)
t[v][k]%=mod;
}
void Build(int v,int i,int j){
if(i==j){
t[v][0]=b[i];
t[v][1]=a[i];
return;
}
int mid=(i+j)/2;
Build(v*2,i,mid);
Build(v*2+1,mid+1,j);
update(v);
}
void UPD(int v,int i,int j,int pos){
if(i==j){
t[v][0]=b[i];
t[v][1]=a[i];
return;
}
int mid=(i+j)/2;
if(pos<=mid)
UPD(v*2,i,mid,pos);
else
UPD(v*2+1,mid+1,j,pos);
update(v);
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
for(int k=1;k<=n;k++){
cin>>a[k];
a[k]%=mod;
}
for(int k=1;k<=n;k++){
cin>>b[k];
b[k]%=mod;
}
Build(1,1,n);
cin>>Q;
while(Q--){
int x,na,nb;
cin>>x>>na>>nb;
a[x]=na%mod;
b[x]=nb%mod;
UPD(1,1,n,x);
int ans=t[1][m];
cout<<ans<<'\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
504 KB |
Output is correct |
2 |
Correct |
11 ms |
504 KB |
Output is correct |
3 |
Correct |
18 ms |
504 KB |
Output is correct |
4 |
Correct |
334 ms |
12468 KB |
Output is correct |
5 |
Correct |
1083 ms |
24152 KB |
Output is correct |
6 |
Correct |
1527 ms |
24092 KB |
Output is correct |
7 |
Correct |
695 ms |
12488 KB |
Output is correct |
8 |
Correct |
387 ms |
23780 KB |
Output is correct |
9 |
Correct |
680 ms |
24096 KB |
Output is correct |
10 |
Correct |
2341 ms |
24144 KB |
Output is correct |