## LOJ 3093 「BJOI2019」光线——数学+思路

$f[i] = b[i]+a[i]*f[i-1]*a[i] + ( b[i]+a[i]*f[i-1]*a[i] ) * b[i+1] * ( b[i]+a[i]*f[i-1]*a[i]) + ...$

#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
int rdn()
{
int ret=0;bool fx=1;char ch=getchar();
while(ch>'9'||ch<'0'){if(ch=='-')fx=0;ch=getchar();}
while(ch>='0'&&ch<='9')ret=ret*10+ch-'0',ch=getchar();
return fx?ret:-ret;
}
const int N=5e5+5,mod=1e9+7;
int upt(int x){while(x>=mod)x-=mod;while(x<0)x+=mod;return x;}
int pw(int x,int k)
{int ret=1;while(k){if(k&1)ret=(ll)ret*x%mod;x=(ll)x*x%mod;k>>=1;}return ret;}

int n,a[N],b[N],f[N],ans;
int main()
{
n=rdn(); int iv=pw(100,mod-2);
for(int i=1;i<=n;i++)
{
a[i]=(ll)rdn()*iv%mod;
b[i]=(ll)rdn()*iv%mod;
}
for(int i=1;i<=n;i++)
{
int x=(b[i]+(ll)a[i]*f[i-1]%mod*a[i])%mod;
f[i]=(ll)x*pw(upt(1-(ll)x*b[i+1]%mod),mod-2)%mod;
}
ans=a[1];
for(int i=2;i<=n;i++)
ans=(1+(ll)b[i]*f[i-1])%mod*ans%mod*a[i]%mod;
printf("%d\n",ans);
return 0;
}

posted on 2019-05-29 09:26  Narh  阅读(82)  评论(0编辑  收藏