#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) 1e5+5;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int n, c;
int a[MAXN], b[MAXN];
const int BS = 350;
int dp[MAXN][21];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
#ifdef Local
freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/int.txt","r",stdin);
freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/out.txt","w",stdout);
#endif
cin>>n>>c;
for(int i = 0; i < n; i++)
cin>>a[i];
for(int i = 0; i < n; i++)
cin>>b[i];
for(int i = 0; i * BS < n; i++){
dp[i][0] = 1;
for(int j = i*BS; j < min((i + 1) * BS, n); j++){
a[j] %= mod;
b[j] %= mod;
int a_cur = a[j], b_cur = b[j];
dp[i][c] = (dp[i][c - 1] * a_cur % mod + dp[i][c] * (a_cur + b_cur) % mod) % mod;
for(int l = c - 1; l > 0; l--){
dp[i][l] = (dp[i][l - 1] * a_cur % mod + dp[i][l] * b_cur % mod) % mod;
}
dp[i][0] = dp[i][0] * b_cur % mod;
}
}
int q;
cin>>q;
for(int i = 0; i < q; i++){
int idx;
cin>>idx;
idx--;
cin>>a[idx]>>b[idx];
a[idx] %= mod;
b[idx] %= mod;
int block = idx / BS;
for(int j = 0; j <= c; j++)
dp[block][j] = 0;
dp[block][0] = 1;
for(int j = block*BS; j < min((block + 1) * BS, n); j++){
int a_cur = a[j], b_cur = b[j];
dp[block][c] = (dp[block][c - 1] * a_cur % mod + dp[block][c] * (a_cur + b_cur) % mod) % mod;
for(int l = c - 1; l > 0; l--){
dp[block][l] = (dp[block][l - 1] * a_cur % mod + dp[block][l] * b_cur % mod) % mod;
}
dp[block][0] = dp[block][0] * b_cur % mod;
}
vector<int> ans(c + 1, 0);
ans[0] = 1;
for(int i = 0; i*BS < n; i++){
vector<int> nans(c + 1, 0);
for(int l = c; l >= 0; l--){
for(int j = c; j >= 0; j--){
nans[(min(c, l + j))] += ans[l] * dp[i][j] % mod;
nans[(min(c, l + j))] %= mod;
}
}
ans = nans;
}
cout<<ans[c]<<endl;
}
#ifdef Local
cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
#endif
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
364 KB |
Output is correct |
2 |
Correct |
33 ms |
492 KB |
Output is correct |
3 |
Correct |
45 ms |
364 KB |
Output is correct |
4 |
Execution timed out |
4038 ms |
3996 KB |
Time limit exceeded |
5 |
Execution timed out |
4030 ms |
3468 KB |
Time limit exceeded |
6 |
Execution timed out |
4041 ms |
3596 KB |
Time limit exceeded |
7 |
Execution timed out |
4080 ms |
3096 KB |
Time limit exceeded |
8 |
Execution timed out |
4093 ms |
3832 KB |
Time limit exceeded |
9 |
Execution timed out |
4059 ms |
3628 KB |
Time limit exceeded |
10 |
Execution timed out |
4083 ms |
3028 KB |
Time limit exceeded |