# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
745598 | bgnbvnbv | Relativnost (COCI15_relativnost) | C++14 | 1134 ms | 26888 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define TASKNAME "codeforce"
#define pb push_back
#define pli pair<int,int>
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=long long;
const ll maxN=1e5+10;
const ll inf=1e18;
const ll mod=1e9+7;
ll c;
struct node
{
int dp[20];
node()
{
for(int i=0;i<c;i++) dp[i]=0;
}
node operator+(const node&o)
{
node ans;
for(int i=0;i<c;i++)
{
for(int j=0;j<=i;j++)
{
ans.dp[i]+=1ll*dp[j]*o.dp[i-j]%mod;
if(ans.dp[i]>=mod) ans.dp[i]-=mod;
}
}
return ans;
}
}st[4*maxN];
ll n,a[maxN],b[maxN];
ll pw(ll x,ll y)
{
if(y==0) return 1;
ll x1=pw(x,y/2);
x1=x1*x1%mod;
if(y&1) x1=x1*x%mod;
return x1;
}
void build(ll id=1,ll l=1,ll r=n)
{
if(l==r)
{
st[id]=node();
st[id].dp[0]=b[l];
st[id].dp[1]=a[l];
return;
}
ll mid=l+r>>1;
build(id*2,l,mid);
build(id*2+1,mid+1,r);
st[id]=st[id*2]+st[id*2+1];
}
void update(ll pos,ll val1,ll val2,ll id=1,ll l=1,ll r=n)
{
if(l==r)
{
st[id].dp[0]=val2;
st[id].dp[1]=val1;
return;
}
ll mid=l+r>>1;
if(pos<=mid) update(pos,val1,val2,id*2,l,mid);
else update(pos,val1,val2,id*2+1,mid+1,r);
st[id]=st[id*2]+st[id*2+1];
}
ll q;
void solve()
{
cin >> n >> c;
ll ans=1;
for(int i=1;i<=n;i++) cin >> a[i];
for(int i=1;i<=n;i++) cin >> b[i],ans*=(b[i]+a[i]),ans%=mod;
build();
cin >> q;
for(int i=1;i<=q;i++)
{
ll p,x,y;
cin >> p >> x >> y;
ll sum=(a[p]+b[p])%mod;
ans=ans*pw(sum,mod-2);
ans%=mod;
a[p]=x;
b[p]=y;
ans=ans*(a[p]+b[p]);
ans%=mod;
update(p,x,y);
ll vd=0;
for(int j=0;j<c;j++)
{
vd+=st[1].dp[j];
if(vd>=mod) vd-=mod;
}
if(ans-vd<0) cout << ans-vd+mod<<'\n';
else cout << ans-vd<<'\n';
}
//cout << st[2].dp[2]<<'\n';
}
int main()
{
fastio
//freopen(TASKNAME".INP","r",stdin);
//freopen(TASKNAME".OUT","w",stdout);
solve();
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |