// dp[i][j] = the number of ways if consider the first i people and j people get colored paintings
/*
* transition
* dp[i][j] = ((dp[i-1][j-1] * a[i]) +(dp[i-1][j]* b[i])) % MOD;
*/
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#define INF 1e9
typedef long long ll;
using namespace std;
const ll MOD = 10007;
ll dp[1005][1005];
void solve()
{
    int n, c; cin >> n >> c;
    vector<ll>a(n + 1), b(n + 1);
    for (int i = 1; i <= n; i++)cin >> a[i];
    for (int i = 1; i <= n; i++)cin >> b[i];
    int q; cin >> q;
    while (q--) {
        ll p, A, B;
        cin >> p >> A >> B;
        a[p] = A;
        b[p] = B;
        for (int i = 0; i <= n; i++) {
            for (int j = 0; j <= n; j++)dp[i][j] = 0;
        }
        dp[1][0] = b[1] % MOD;
        dp[1][1] = a[1] % MOD;
        for (int i = 2; i <= n; i++) {
            for (int j = 0; j <= i; j++) {
                if (j == 0) {
                    dp[i][j] = (dp[i][j] + (dp[i - 1][j] * b[i])) % MOD;
                }
                else {
                    dp[i][j] = (dp[i][j] + ((dp[i - 1][j - 1] * a[i]) % MOD + (dp[i - 1][j] * b[i]) % MOD)) % MOD;
                }
            }
        }
        ll ans = 0;
        for (int j = c; j <= n; j++)ans = (ans + dp[n][j]) % MOD;
        cout << ans << "\n";
    }
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;// cin >> t;
    while (t--) solve();
    return 0;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |