LOJ # 3045. "ZJOI2019" switch

Portal

Immortal title

BIG # 3045

Portal

\(P=\sum p_i\)

For the first \ (I \) position, considering it \ (n-\) valid probability after times, which is arranged to generate exponential function \ (F_i (x) \)

\[ \begin{aligned} F_i(x) &=\sum_{j\bmod 2=s_i}\left(p_i\over P\right)^j{x^j\over j!}\\ &={e^{p_ix\over P}+(-1)^{s_i}e^{-p_ix\over P}\over 2}\\ \end{aligned} \]

So the total probability \ (EGF \) is

\[ \begin{aligned} F(x)=\prod_{i=1}^n {e^{p_ix\over P}+(-1)^{s_i}e^{-p_ix\over P}\over 2} \end{aligned} \]

Here, however, it is possible to finish the \ (\ n) before the step to reach the final state, this situation can be considered after the first reaches the end state, the number of rings to go back to the end state

We consider walked \ (n \) Step back to the starting point of probability

\[ \begin{aligned} G(x)=\prod_{i=1}^n {e^{p_ix\over P}+e^{-p_ix\over P}\over 2} \end{aligned} \]

Order \ (H (x) \) represents the answer generating function, so that these three functions \ (of OGF \) are \ (F, G, H \) , there

\[ \begin{aligned} h(x)g(x)=f(x)\\ h(x)={f(x)\over g(x)} \end{aligned} \]

Since \ (h (x) \) is the probability generating function, so the answer is \ (h '(1) \ )

due to

\[ \begin{aligned} h'(x)={f'(x)g(x)-g'(x)f(x)\over g^2(x)} \end{aligned} \]

We \ (F (x) \) written in the form

\[ \begin{aligned} F(x)=\sum_{i=-P}^P a_ie^{ix\over P} \end{aligned} \]

Then the corresponding \ (f (x) \) is

\[ \begin{aligned} f(x)=\sum_{i=-P}^P a_i{1\over 1-{ix\over P}} \end{aligned} \]

However, we found that when \ (x = 1 \) when \ (f (x) \) and \ (g (x) \) does not converge (when \ (i = P \) back when the score of the form \ ({1 \ 0} over \) ), so we need to \ (f (x) \) and \ (g (x) \) simultaneously multiplying \ (\ prod_ {i = 1 } ^ n \ left (1- {ix \ P} over \ right) \) , this does not affect the answers. At this time, \ (f (x) \) is

\[ \begin{aligned} f(x)=\sum_{i=-P}^P a_i\prod_{j\neq i}\left({1-{jx\over P}}\right) \end{aligned} \]

When \ (x = 1 \) , the rear \ (j = P \) can lead to back \ (0 \) , it is

\[ \begin{aligned} f(1)=a_P\prod_{j\neq P}\left({1-{jx\over P}}\right) \end{aligned} \]

For \ (F '(X) \) , because

\[ \begin{aligned} \left(\prod_i (1+a_ix)\right)'=\sum_i a_i\prod_{j\neq i} (1+a_jx) \end{aligned} \]

We \ (f '(x) \ ) divided into two portions calculation part \ (i \ neq P \) , there is

\[ \begin{aligned} A(x)=\sum_{i\neq P}a_i\sum_{k\neq i}\left(-k\over P\right)\prod_{j\neq i,j\neq k}\left(1-{jx\over P}\right) \end{aligned} \]

When \ (x = 1 \) and \ (k \ neq P \) when followed by \ (0 \) , so

\[ \begin{aligned} A(1)=-\sum_{i\neq P}a_i\prod_{j\neq i,j\neq P}\left(1-{j\over P}\right) \end{aligned} \]

While the back (i = P \) \ portion, there

\[ \begin{aligned} B(1)=a_P\sum_{i\neq P}\left(-{i\over P}\right)\prod_{j\neq i,j\neq P}\left(1-{j\over P}\right) \end{aligned} \]

and so

\[ \begin{aligned} f'(1) &=A(1)+B(1)\\ &=-\prod_{i\neq P}\left(1-\frac{i}{P}\right)\left(\sum_{j\neq P}\frac{a_j}{1-\frac{j}{P}}+a_P\sum_{j\neq P}\frac{\frac{j}{P}}{1-\frac{j}{P}}\right) \end{aligned} \]

\ (g '(x) \ ) similarly can be directly substituted into the

It is said that you can continue to simplify, but I really do not understand the behind

//quming
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int P=998244353,inv2=(P+1)>>1;
inline void upd(R int &x,R int y){(x+=y)>=P?x-=P:0;}
inline int inc(R int x,R int y){return x+y>=P?x+y-P:x+y;}
inline int dec(R int x,R int y){return x-y<0?x-y+P:x-y;}
inline int mul(R int x,R int y){return 1ll*x*y-1ll*x*y/P*P;}
int ksm(R int x,R int y){
    R int res=1;
    for(;y;y>>=1,x=mul(x,x))(y&1)?res=mul(res,x):0;
    return res;
}
const int N=5e4+5;
int f[N<<1],g[N<<1],tmp[N<<1],s[N],p[N],n,res,sum;
inline int calc(int *f){
    R int res=1,ism=ksm(sum,P-2);
    fp(i,-sum,sum-1){
        R int iv=mul(inc(i,P),ism);
        res=mul(res,P+1-iv);
    }
    return mul(res,f[sum+N]);
}
inline int dir(int *f){
    R int res=1,ret=0,ism=ksm(sum,P-2);
    fp(i,-sum,sum-1){
        R int iv=mul(inc(i,P),ism);
        res=mul(res,P+1-iv);
        upd(ret,mul(ksm(P+1-iv,P-2),inc(f[i+N],mul(f[sum+N],iv))));
    }
    return inc(0,P-mul(res,ret));
}
int main(){
//  freopen("testdata.in","r",stdin);
    scanf("%d",&n);
    fp(i,1,n)scanf("%d",&s[i]);
    fp(i,1,n)scanf("%d",&p[i]);
    f[N]=g[N]=1;
    fp(i,1,n){
        R int v=p[i];
        sum+=v;
        fp(j,-sum,sum)tmp[j+N]=0;
        R int c1=inv2,c2=s[i]?P-inv2:inv2;
        fp(j,-sum+v,sum)upd(tmp[j+N],mul(c1,f[j+N-v]));
        fd(j,sum-v,-sum)upd(tmp[j+N],mul(c2,f[j+N+v]));
        fp(j,-sum,sum)f[j+N]=tmp[j+N],tmp[j+N]=0;
        fp(j,-sum+v,sum)upd(tmp[j+N],mul(c1,g[j+N-v]));
        fd(j,sum-v,-sum)upd(tmp[j+N],mul(c1,g[j+N+v]));
        fp(j,-sum,sum)g[j+N]=tmp[j+N];
    }
    R int res=calc(g);
    res=ksm(res,P-2),res=mul(res,res);
    res=mul(res,inc(mul(dir(f),calc(g)),P-mul(dir(g),calc(f))));
    printf("%d\n",res);
    return 0;
}

Guess you like

Origin www.cnblogs.com/yuanquming/p/12056239.html