传送门
设
m
=
2
n
−
1
m=2^n-1
m=2n−1
显然可以得到
∀
i
>
0
\forall i>0
∀i>0
f
[
i
]
=
1
+
∑
j
f
[
i
⊕
j
]
p
[
j
]
f[i]=1+\sum_{j}f[i\oplus j]p[j]
f[i]=1+j∑f[i⊕j]p[j]
f
[
i
]
−
1
=
∑
j
=
0
m
f
[
i
⊕
j
]
p
[
j
]
f[i]-1=\sum_{j=0}^{m}f[i\oplus j]p[j]
f[i]−1=j=0∑mf[i⊕j]p[j]
这是一个异或卷积
即
[
f
0
,
f
1
.
.
.
.
f
m
]
⨁
[
p
0
,
p
1
.
.
.
p
m
]
=
[
?
,
f
1
−
1
,
f
2
−
1....
f
m
−
1
]
[f_0,f_1....f_m]\bigoplus[p_0,p_1...p_m]=[?,f_1-1,f_2-1....f_m-1]
[f0,f1....fm]⨁[p0,p1...pm]=[?,f1−1,f2−1....fm−1]
由于考虑到
∑
p
=
1
\sum p=1
∑p=1
所以卷积前后的和应该是不变的
也就是
?
=
f
0
+
m
?=f_0+m
?=f0+m
再考虑将
p
0
=
p
0
−
1
p_0=p_0-1
p0=p0−1
那么异或卷积后的函数就变成了
[
m
,
−
1
,
−
1
,
.
.
.
.
−
1
]
[m,-1,-1,....-1]
[m,−1,−1,....−1]
设这个数组为
g
g
g
再考虑做异或卷积除法还原原数组
f
w
t
fwt
fwt之后
f
′
=
f'=
f′=
g
′
g'
g′乘上
p
′
p'
p′的逆元
再
i
f
w
t
ifwt
ifwt即可
但是问题在于可以知道
f
w
t
fwt
fwt之后
g
0
′
,
p
0
′
g'_0,p'_0
g0′,p0′都是
0
0
0,没法求逆元
但是可以知道
f
0
=
0
f_0=0
f0=0
于是可以先假设
f
0
′
=
0
,
i
f
w
t
f'_0=0,ifwt
f0′=0,ifwt回去之后,若
f
0
=
−
x
f_0=-x
f0=−x
按照
f
w
t
fwt
fwt的定义,就是
f
0
′
f'_0
f0′少算了
x
x
x
于是所有全部加上
x
x
x即可
#include<bits/stdc++.h>
using namespace std;
#define cs const
#define re register
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define fi first
#define se second
#define bg begin
cs int RLEN=1<<20|1;
inline char gc(){
static char ibuf[RLEN],*ib,*ob;
(ib==ob)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
return (ib==ob)?EOF:*ib++;
}
inline int read(){
char ch=gc();
int res=0;bool f=1;
while(!isdigit(ch))f^=ch=='-',ch=gc();
while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
return f?res:-res;
}
inline ll readll(){
char ch=gc();
ll res=0;bool f=1;
while(!isdigit(ch))f^=ch=='-',ch=gc();
while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
return f?res:-res;
}
inline int readstring(char *s){
int top=0;char ch=gc();
while(isspace(ch))ch=gc();
while(!isspace(ch)&&ch!=EOF)s[++top]=ch,ch=gc();
return top;
}
template<typename tp>inline void chemx(tp &a,tp b){a<b?a=b:0;}
template<typename tp>inline void chemn(tp &a,tp b){a>b?a=b:0;}
cs int mod=998244353;
inline int add(int a,int b){return (a+=b)>=mod?(a-mod):a;}
inline int dec(int a,int b){a-=b;return a+(a>>31&mod);}
inline int mul(int a,int b){static ll r;r=1ll*a*b;return (r>=mod)?(r%mod):r;}
inline void Add(int &a,int b){(a+=b)>=mod?(a-=mod):0;}
inline void Dec(int &a,int b){a-=b,a+=a>>31&mod;}
inline void Mul(int &a,int b){static ll r;r=1ll*a*b;a=(r>=mod)?(r%mod):r;}
inline int ksm(int a,int b,int res=1){if(a==0&&b==0)return 0;for(;b;b>>=1,Mul(a,a))(b&1)&&(Mul(res,a),1);return res;}
inline int Inv(int x){return ksm(x,mod-2);}
inline int fix(ll x){return x%=mod,(x<0)?x+mod:x;}
cs int N=19,M=(1<<N)|1;
int f[M],p[M],n,m,s;
inline void fwt(int *f,int lim,int kd){
for(int mid=1,a0,a1;mid<lim;mid<<=1)
for(int i=0;i<lim;i+=mid<<1)
for(int j=0;j<mid;j++)
a0=f[i+j],a1=f[i+j+mid],f[i+j]=add(a0,a1),f[i+j+mid]=dec(a0,a1);
if(kd==-1)
for(int i=0,iv=Inv(lim);i<lim;i++)Mul(f[i],iv);
}
int main(){
#ifdef Stargazer
freopen("lx.in","r",stdin);
#endif
n=read(),m=1<<n;
for(int i=0;i<m;i++){
p[i]=read(),Add(s,p[i]);
}s=Inv(s);
for(int i=0;i<m;i++)Mul(p[i],s);
Dec(p[0],1),f[0]=m-1;
for(int i=1;i<m;i++)f[i]=mod-1;
fwt(f,m,1),fwt(p,m,1);
for(int i=1;i<m;i++)Mul(f[i],Inv(p[i]));
f[0]=0,fwt(f,m,-1);
for(int i=0;i<m;i++)cout<<dec(f[i],f[0])<<"\n";
return 0;
}