FWT模板:
1 void FWT(int a[],int n) 2 { 3 for(int d=1;d<n;d<<=1) //你甚至可以RANDOMSHUFFLE 4 for(int m=d<<1,i=0;i<n;i+=m) 5 for(int j=0;j<d;j++) 6 { 7 int x=a[i+j],y=a[i+j+d]; 8 a[i+j]=(x+y)%mod,a[i+j+d]=(x-y+mod)%mod; 9 //xor:a[i+j]=x+y,a[i+j+d]=x-y; 10 //and:a[i+j]=x+y; 11 //or:a[i+j+d]=x+y; 12 } 13 } 14 15 void UFWT(int a[],int n) 16 { 17 for(int d=1;d<n;d<<=1) //你甚至可以RANDOMSHUFFLE 18 for(int m=d<<1,i=0;i<n;i+=m) 19 for(int j=0;j<d;j++) 20 { 21 int x=a[i+j],y=a[i+j+d]; 22 a[i+j]=1LL*(x+y)*rev%mod,a[i+j+d]=(1LL*(x-y)*rev%mod+mod)%mod; 23 //xor:a[i+j]=(x+y)/2,a[i+j+d]=(x-y)/2; 24 //and:a[i+j]=x-y; 25 //or:a[i+j+d]=y-x; 26 } 27 } 28 void solve(int a[],int b[],int n) 29 { 30 FWT(a,n); 31 FWT(b,n); 32 for(int i=0;i<n;i++) a[i]=1LL*a[i]*b[i]%mod; 33 UFWT(a,n); 34 }