好题!
(以下 为值域)
设 表示考虑前 个数,两人 xor 和为 的方案数。
转移:。
写出每个 的集合幂级数:。
于是 。
此处的卷积为 xor 卷积。
直接用 FWT 求完点值然后乘的复杂度是 ,和暴力 DP 没有区别。
记 为 的 FWT-xor 点值,根据计算式,可以发现:,只有 和 两种取值。
记 为 的 FWT-xor 点值表示,有 。
只要求出 ,就能通过快速幂求出 。
尝试构造关于 的方程。
考虑求出 。含义是对 FWT-xor 点值求和。根据 FWT-xor 是线性变换,可以先求和,再做 FWT-xor,也就是说直接算每个 的贡献,复杂度 。
容易解出 ,快速幂求出 后做 IFWT 即可获得 ,答案为常数项 。
复杂度 。
#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;
}