#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int nx=1e5+5, cx=21, mod=10007;
ll n, c, dp[nx][cx], a[nx], b[nx], q, idx, x, y, res;
int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n>>c;
    for (int i=1; i<=n; i++) cin>>a[i];
    for (int i=1; i<=n; i++) cin>>b[i];
    dp[0][0]=1;
    cin>>q;
    while (q--)
    {
        cin>>idx>>x>>y;
        a[idx]=x, b[idx]=y;
        for (int i=1; i<=n; i++)
        {
            for (int j=0; j<=c; j++)
            {
                dp[i][j]=dp[i-1][j]*b[i];
                if (j>0) dp[i][j]=(dp[i][j]+dp[i-1][j-1]*a[i])%mod;
                if (j==c) dp[i][j]=(dp[i][j]+dp[i-1][j]*a[i])%mod;
                //cout<<i<<' '<<j<<' '<<dp[i][j]<<'\n';
            }
        }
        cout<<dp[n][c]<<'\n';
    }
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |