#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define fs first
#define sc second
using namespace std;
const int MOD = 10007;
const int N = 21;
int n, C, Q;
vector<int> a, b;
int count(int x) {
int cnt = 0;
while (x) {
cnt += (x & 1);
x >>= 1;
}
return cnt;
}
signed main(){
cin >> n >> C;
a.resize(n);
b.resize(n);
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) cin >> b[i];
cin >> Q;
while (Q--) {
int p, a1, b1;
cin >> p >> a1 >> b1;
p--;
a[p] = a1;
b[p] = b1;
vector<pair<int, int>> c(n);
for (int i = 0; i < n; i++) {
c[i] = {a[i], b[i]};
}
int ans = 0;
int total = 1LL << n;
for (int mask = 0; mask < total; mask++) {
int cnt = count(mask);
if (cnt < C) continue;
int cc = 1;
for (int i = 0; i < n; i++) {
if (mask & (1LL << i)) {
cc = cc * a[i] % MOD;
} else {
cc = cc * b[i] % MOD;
}
}
ans = (ans + cc) % MOD;
}
cout << ans << endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |