FWT板子

板子:

#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N = 17;
const int MOD = 998244353;
template<typename T>
inline void read(T&x)
{
    T f = 1,c = 0;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){c=c*10+ch-'0';ch=getchar();}
    x = f*c;
}
int n;
ll inv_2=(MOD+1)/2;
ll a[(1<<N)+5],b[(1<<N)+5],c[(1<<N)+5];
void Mod(ll&x){if(x>=MOD)x-=MOD;}
void fwt_or(ll *a,int len,int k)
{
    for(int i=1;i<len;i<<=1)
        for(int j=0;j<len;j+=(i<<1))
            for(int o=0;o<i;o++)
            {
                if(k==1)Mod(a[j+o+i]+=a[j+o]);
                else    Mod(a[j+o+i]+=-a[j+o]+MOD);
            }
}
void fwt_and(ll *a,int len,int k)
{
    for(int i=1;i<len;i<<=1)
        for(int j=0;j<len;j+=(i<<1))
            for(int o=0;o<i;o++)
            {
                if(k==1)Mod(a[j+o]+=a[j+o+i]);
                else    Mod(a[j+o]+=-a[j+o+i]+MOD);
            }
}
void fwt_xor(ll *a,int len,int k)
{
    for(int i=1;i<len;i<<=1)
        for(int j=0;j<len;j+=(i<<1))
            for(int o=0;o<i;o++)
            {
                int w1 = a[j+o],w2 = a[j+o+i];
                a[j+o] = (w1+w2)%MOD;
                a[j+o+i] = (w1-w2+MOD)%MOD;
                if(k==-1)a[j+o]=a[j+o]*inv_2%MOD,a[j+o+i]=a[j+o+i]*inv_2%MOD;
            }
}
void mul()
{
    for(int i=0;i<(1<<n);i++)
        c[i] = a[i]*b[i]%MOD;
}
void print()
{
    for(int i=0;i<(1<<n);i++)
        printf("%lld ",c[i]);
    puts("");
}
int main()
{
    read(n);int len = (1<<n);
    for(int i=0;i<len;i++)
        read(a[i]);
    for(int i=0;i<len;i++)
        read(b[i]);
    fwt_or(a,len,1),fwt_or(b,len,1);
    mul();
    fwt_or(c,len,-1);
    print();
    fwt_or(a,len,-1),fwt_or(b,len,-1);
    fwt_and(a,len,1),fwt_and(b,len,1);
    mul();
    fwt_and(c,len,-1);
    print();
    fwt_and(a,len,-1),fwt_and(b,len,-1);
    fwt_xor(a,len,1),fwt_xor(b,len,1);
    mul();
    fwt_xor(c,len,-1);
    print();
    fwt_xor(a,len,-1),fwt_xor(b,len,-1);
    return 0;
}

 

转载于:https://www.cnblogs.com/LiGuanlin1124/p/10523903.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值