[UNR #2] 黎明前的巧克力
好题!
题面
(以下
设
转移:
写出每个
于是
此处的卷积为 xor 卷积。
直接用 FWT 求完点值然后乘的复杂度是
记
记
只要求出
尝试构造关于
考虑求出
容易解出
复杂度
#include<bits/stdc++.h>
using namespace std;
const int N=2e6+7,P=998244353;
int n,m,s[N],c[N],h[N],mi[N];
inline void fwt(int *f,int n,int op)
{
int len,i,j,x,y;
for(len=1;len<n;len<<=1)
for(i=0;i<n;i+=len<<1)
for(j=0;j<len;++j)
{
x=f[i+j],y=f[i+j+len];
f[i+j]=1ll*op*(x+y)%P;
f[i+j+len]=1ll*op*(x+P-y)%P;
}
}
int main()
{
ios::sync_with_stdio(0),cin.tie(0);
int i,x;
cin>>n,m=1<<20;
s[0]=n,mi[0]=1;
for(i=1;i<=n;++i) cin>>x,s[x]+=2,mi[i]=3ll*mi[i-1]%P;
fwt(s,m,1);
for(i=0;i<m;++i) c[i]=(s[i]+n)%P/4;
for(i=0;i<m;++i) h[i]=1ll*mi[c[i]]*((n-c[i])&1?P-1:1)%P;
fwt(h,m,(P+1)>>1);
cout<<(h[0]>0?h[0]-1:P-1)<<'\n';
return 0;
}