#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<float.h>
#include<limits.h>
#include <cassert>
#include<cmath>
#include<set>
#include<algorithm>
#include <iomanip>
#include<numeric> //gcd(a,b)
#include<bitset>
using namespace std;
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
using namespace std;
#define int long long
#define double long double
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-loops")
const int mod=10007,mxn=1e5,lg=22,inf=1e18,minf=-1e18,Mxn=100000;
int n,c,q,A[mxn+10],B[mxn+10],dp[22];
int inverse(int a){
int ex=mod-2,ans=1;
while(ex){
if(ex&1)ans=(ans*a)%mod;
a=(a*a)%mod;
ex>>=1;
}
return ans;
}
int32_t main(){
fastio
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]=1;
int ans=1;
for(int i=1;i<=n;i++){
A[i]%=mod;
B[i]%=mod;
for(int j=c;j>=0;j--){
dp[j]=(dp[j]*B[i])%mod;
if(j)dp[j]=(dp[j]+(dp[j-1]*A[i])%mod)%mod;
}
}
for(int i=1;i<=n;i++)ans=((ans*A[i])%mod+(ans*B[i])%mod)%mod;
cin>>q;
while(q--){
int pos,x,y;cin>>pos>>x>>y;
x%=mod;
y%=mod;
int inv=inverse(B[pos]);
for(int j=0;j<c;j++){
if(j)dp[j]=((dp[j]-(dp[j-1]*A[pos])%mod)+mod)%mod;
dp[j]=(dp[j]*inv)%mod;
}
ans=ans*inverse(A[pos]+B[pos]);
A[pos]=x;
B[pos]=y;
for(int j=c-1;j>=0;j--){
dp[j]=(dp[j]*B[pos])%mod;
if(j)dp[j]=(dp[j]+(dp[j-1]*A[pos])%mod)%mod;
}
ans=((ans*A[pos])%mod+(ans*B[pos])%mod)%mod;
int ra=ans;
for(int j=0;j<c;j++)ra=((ra-dp[j])+mod)%mod;
cout<<ra<<'\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Incorrect |
44 ms |
1364 KB |
Output isn't correct |
5 |
Incorrect |
66 ms |
1872 KB |
Output isn't correct |
6 |
Incorrect |
65 ms |
1952 KB |
Output isn't correct |
7 |
Incorrect |
50 ms |
1504 KB |
Output isn't correct |
8 |
Correct |
53 ms |
1880 KB |
Output is correct |
9 |
Incorrect |
77 ms |
1620 KB |
Output isn't correct |
10 |
Incorrect |
84 ms |
1624 KB |
Output isn't correct |