LOJ#3093. 「BJOI2019」光线
从下到上把两面镜子合成一个
新的镜子是((frac{a_{i}a_{i + 1}}{1 - b_{i}b_{i + 1}},b_{i} + frac{a_{i}^{2}b_{i}}{1 - b_{i}b_{i + 1}}))
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('
')
#define eps 1e-10
#define MAXN 500005
#define ba 47
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
const int MOD = 1000000007;
int N;
int a[MAXN],b[MAXN];
int inc(int a,int b) {
return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
return 1LL * a * b % MOD;
}
int fpow(int x,int c) {
int res = 1,t = x;
while(c) {
if(c & 1) res = mul(res,t);
t = mul(t,t);
c >>= 1;
}
return res;
}
void Solve() {
read(N);
int iv = fpow(100,MOD - 2);
for(int i = 1 ; i <= N ; ++i) {
read(a[i]);read(b[i]);
a[i] = mul(a[i],iv);b[i] = mul(b[i],iv);
}
for(int i = N - 1 ; i >= 1 ; --i) {
int inv = fpow(inc(1,MOD - mul(b[i],b[i + 1])),MOD - 2);
int na = mul(mul(a[i],a[i + 1]),inv);
int nb = b[i];
int t = mul(mul(a[i],a[i]),b[i + 1]);
nb = inc(nb,mul(t,inv));
a[i] = na;b[i] = nb;
}
out(a[1]);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}