链接
题解
真是神奇的脑筋急转弯题
通过观察发现 b k = ∑ i x o r j = k a i x j b_k = \sum_{i\ xor\ j=k} a_i x_j bk=∑i xor j=kaixj
通过 f w t fwt fwt处理就可以了
代码
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define iinf 0x3f3f3f3f
#define linf (1ll<<60)
#define eps 1e-8
#define maxn 1000010
#define maxe 1000010
#define cl(x) memset(x,0,sizeof(x))
#define rep(i,a,b) for(i=a;i<=b;i++)
#define em(x) emplace(x)
#define emb(x) emplace_back(x)
#define emf(x) emplace_front(x)
#define fi first
#define se second
#define de(x) cerr<<#x<<" = "<<x<<endl
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll read(ll x=0)
{
ll c, f(1);
for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-f;
for(;isdigit(c);c=getchar())x=x*10+c-0x30;
return f*x;
}
#define mod 1'000'000'007ll
struct EasyMath
{
ll prime[maxn], phi[maxn], mu[maxn];
bool mark[maxn];
ll fastpow(ll a, ll b, ll c)
{
ll t(a%c), ans(1ll);
for(;b;b>>=1,t=t*t%c)if(b&1)ans=ans*t%c;
return ans;
}
void exgcd(ll a, ll b, ll &x, ll &y)
{
if(!b){x=1,y=0;return;}
ll xx, yy;
exgcd(b,a%b,xx,yy);
x=yy, y=xx-a/b*yy;
}
ll inv(ll x, ll p) //p是素数
{return fastpow(x%p,p-2,p);}
ll inv2(ll a, ll p)
{
ll x, y;
exgcd(a,p,x,y);
return (x+p)%p;
}
void shai(ll N)
{
ll i, j;
for(i=2;i<=N;i++)mark[i]=false;
*prime=0;
phi[1]=mu[1]=1;
for(i=2;i<=N;i++)
{
if(!mark[i])prime[++*prime]=i, mu[i]=-1, phi[i]=i-1;
for(j=1;j<=*prime and i*prime[j]<=N;j++)
{
mark[i*prime[j]]=true;
if(i%prime[j]==0)
{
phi[i*prime[j]]=phi[i]*prime[j];
break;
}
mu[i*prime[j]]=-mu[i];
phi[i*prime[j]]=phi[i]*(prime[j]-1);
}
}
}
ll CRT(vector<ll> a, vector<ll> m) //要求模数两两互质
{
ll M=1, ans=0, n=a.size(), i;
for(i=0;i<n;i++)M*=m[i];
for(i=0;i<n;i++)(ans+=a[i]*(M/m[i])%M*inv2(M/m[i],m[i]))%=M;
return ans;
}
}em;
struct FWT
{
ll a[maxn], n;
void init(ll N)
{
for(n=1;n<=N;n<<=1);
for(ll i=0;i<n;i++)a[i]=0;
}
void FWT_or(ll opt)
{
for(ll i=1;i<n;i<<=1)
for(ll p=i<<1,j=0;j<n;j+=p)
for(ll k=0;k<i;++k)
if(opt==1)a[i+j+k]=(a[j+k]+a[i+j+k])%mod;
else a[i+j+k]=(a[i+j+k]-a[j+k])%mod;
}
void FWT_and(ll opt)
{
for(ll i=1;i<n;i<<=1)
for(ll p=i<<1,j=0;j<n;j+=p)
for(ll k=0;k<i;++k)
if(opt==1)a[j+k]=(a[j+k]+a[i+j+k])%mod;
else a[j+k]=(a[j+k]-a[i+j+k])%mod;
}
void FWT_xor(ll opt)
{
ll inv2=em.fastpow(2,mod-2,mod);
for(ll i=1;i<n;i<<=1)
for(ll p=i<<1,j=0;j<n;j+=p)
for(ll k=0;k<i;++k)
{
ll x=a[j+k], y=a[i+j+k];
a[j+k]=(x+y)%mod, a[i+j+k]=(x-y)%mod;
if(opt==-1)a[j+k]=a[j+k]*inv2%mod, a[i+j+k]=a[i+j+k]*inv2%mod;
}
}
void fwt(ll type, ll opt)
{
if(type==1)FWT_or(opt);
else if(type==2)FWT_and(opt);
else FWT_xor(opt);
}
void mult(FWT& b, ll type)
{
if(n!=b.n){cerr<<"fwt error!\n";return;}
fwt(type,1), b.fwt(type,1);
for(ll i=0;i<n;i++)a[i]=(ll)a[i]*b.a[i]%mod;
fwt(type,-1), b.fwt(type,-1);
}
}a, b, x;
int main()
{
ll n, i;
n=read();
a.init(n-1), b.init(n-1), x.init(n-1);
rep(i,0,n-1)a.a[i]=read();
rep(i,0,n-1)b.a[i]=read();
a.FWT_xor(+1);
b.FWT_xor(+1);
rep(i,0,n-1)x.a[i]=b.a[i]*em.inv(a.a[i],mod)%mod;
x.FWT_xor(-1);
rep(i,0,n-1)printf("%lld\n",(x.a[i]+mod)%mod);
return 0;
}