제출 #899983

#제출 시각아이디문제언어결과실행 시간메모리
8999838pete8Relativnost (COCI15_relativnost)C++17
56 / 140
89 ms5560 KiB
#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++){ for(int j=c;j>=0;j--){ dp[j]=(dp[j]*B[i])%mod; if(j)dp[j]+=(dp[j-1]*A[i])%mod; dp[j]%=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; 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-1]*A[pos])%mod; dp[j]%=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 timeMemoryGrader output
Fetching results...