#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
const int mod = (int) 1e4+7;
const int MAXN = (int) 3e5+5;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n, c, q;
ll a[MAXN], b[MAXN];
ll dp[MAXN][25];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
#ifdef Local
freopen("../IO/int.txt","r",stdin);
freopen("../IO/out.txt","w",stdout);
#endif
cin>>n>>c;
for(int i = 1; i <= n; i++){
cin>>a[i];
}
ll cur = 1;
for(int i = 1; i <= n; i++){
cin>>b[i];
cur *= (a[i] + 1)*(b[i] + 1) - 1;
cur %= mod;
}
/*for(int i = 1; i <= n; i++){
for(int j = 1; j < c; j++){
dp[i][j] = dp[i - 1][j - 1]*(b[i] + 1)%mod*a[i]% mod;
dp[i][j] += dp[i - 1][j]*(b[i])%mod;
dp[i][j] %= mod;
}
}*/
cin>>q;
while(q--){
int kis, an, bn;
cin>>kis>>an>>bn;
a[kis] = an;
b[kis] = bn;
ll cur = 1;
dp[0][0] = 1;
for(int i = 1; i <= n; i++){
cur *= a[i] + b[i];
cur %= mod;
}
for(int i = 1; i <= n; i++){
dp[i][0] = dp[i - 1][0]*b[i]%mod;
dp[i][0] %= mod;
//cout<<i<<endl;
//cout<<dp[i][0]<<" ";
for(int j = 1; j < c; j++){
dp[i][j] = dp[i - 1][j - 1]*a[i]% mod;
dp[i][j] += dp[i - 1][j]*b[i]%mod;
dp[i][j] %= mod;
// cout<<dp[i][j]<<" ";
}
//cout<<endl;
}
ll cik = 0;
for(int j = 0; j < c; j++){
cik += dp[n][j];
cik %= mod;
}
cout<<(cur - cik + mod)%mod<<endl;
}
#ifdef Local
cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
#endif
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
66 ms |
632 KB |
Output is correct |
2 |
Correct |
88 ms |
632 KB |
Output is correct |
3 |
Correct |
98 ms |
504 KB |
Output is correct |
4 |
Execution timed out |
4024 ms |
12740 KB |
Time limit exceeded |
5 |
Execution timed out |
4021 ms |
20452 KB |
Time limit exceeded |
6 |
Execution timed out |
4035 ms |
21496 KB |
Time limit exceeded |
7 |
Execution timed out |
4040 ms |
15096 KB |
Time limit exceeded |
8 |
Execution timed out |
4011 ms |
21468 KB |
Time limit exceeded |
9 |
Execution timed out |
4098 ms |
17784 KB |
Time limit exceeded |
10 |
Execution timed out |
4019 ms |
16784 KB |
Time limit exceeded |