卷积:ans_S=\sum f_T*g_{S|T}

· · 个人记录

不考虑正确性:直接对 f 做高维前缀和,f 乘上 g,再反着做高维后缀和。

错因显然,对 g 做带 -1^{popcount} 系数的高维后缀和预处理即可。

checker

#pragma target("avx512f,sse2,sse3,sse4,sse4.2")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned ll

const ll N=1e6+5;
ll n=5,K;
ull f[N],g[N],F[N],G[N];

ull bf[N],test[N];

mt19937 rnd(time(0));

int main(){
    K=(1<<n);
    for(int i=0;i<K;i++) f[i]=F[i]=rnd();
    for(int i=0;i<K;i++) g[i]=G[i]=rnd();

    //      bf

    for(int i=0;i<K;i++)
        for(int j=0;j<K;j++)
            bf[i]+=f[j]*g[i|j];

    //      test

    for(int b=0;b<n;b++)
        for(int i=0;i<K;i++)
            if((i>>b)&1){
                F[i]+=F[i^(1<<b)];
                G[i^(1<<b)]-=G[i];}
    for(int i=0;i<K;i++) test[i]=F[i]*G[i];
    for(int b=0;b<n;b++)
        for(int i=0;i<K;i++)
            if((i>>b)&1)
                test[i^(1<<b)]+=test[i];

    //      check

    for(int i=0;i<K;i++) printf("%llu ",bf[i]); printf("\n");
    for(int i=0;i<K;i++) printf("%llu ",test[i]); printf("\n");
    for(int i=0;i<K;i++) assert(bf[i]==test[i]);

    return 0;}