//Place your snippets for cpp here. Each snippet is defined under a snippet name and has a prefix, body and 
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the 
// same ids are connected.
// prefix 的格式要求是 acm-[一级标题编号].[二级标题编号][该代码片段的英文简称]
// description 的格式要求是 "插入 [该代码片段的中文名]"

{
    "多项式 位运算卷积": {
        "prefix": "acm-7.4FWT",
        "body": [
            "#include<algorithm>",
            "#include<cstring>",
            "#include<cstdio>",
            "#include<cmath>",
            "#define LD double",
            "#define LL long long",
            "#define Re register int",
            "using namespace std;",
            "const int N=131072+3,P=998244353;",
            "int n,m,inv2,A[N],B[N];",
            "inline void in(Re &x){",
            "    int f=0;x=0;char c=getchar();",
            "    while(c<'0'||c>'9')f|=c=='-',c=getchar();",
            "    while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();",
            "    x=f?-x:x;",
            "}",
            "inline int inv(Re x){",
            "\tRe s=1,k=P-2;",
            "\twhile(k){",
            "\t\tif(k&1)s=(LL)s*x%P;",
            "\t\tx=(LL)x*x%P,k>>=1;",
            "\t}",
            "\treturn s;",
            "}",
            "int id,f[N],g[N];",
            "inline void FWT(Re *f,Re n,Re op){",
            "\tfor(Re p=2;p<=n;p<<=1)",
            "\t\tfor(Re st=1,len=p>>1;st<n;st+=p)",
            "\t\t\tfor(Re j=st;j<=st+len-1;++j)",
            "\t\t\t\tif(id==1)(f[j+len]+=(op?P-f[j]:f[j]))%=P;",
            "\t\t\t\telse if(id==2)(f[j]+=(op?P-f[j+len]:f[j+len]))%=P;",
            "\t\t\t\telse{",
            "\t\t\t\t\tRe g0=f[j],g1=f[j+len];",
            "\t\t\t\t\tf[j]=(g0+g1)%P,f[j+len]=(g0-g1+P)%P;",
            "\t\t\t\t\tif(op)f[j]=(LL)f[j]*inv2%P,f[j+len]=(LL)f[j+len]*inv2%P;",
            "\t\t\t\t}",
            "}",
            "inline void sakura(Re *A,Re *B,Re n,Re id_){",
            "\tfor(Re i=1;i<=n;++i)f[i]=A[i],g[i]=B[i];id=id_;",
            "\tFWT(f,n,0),FWT(g,n,0);",
            "\tfor(Re i=1;i<=n;++i)f[i]=(LL)f[i]*g[i]%P;",
            "\tFWT(f,n,1);",
            "\tfor(Re i=1;i<=n;++i)printf(\"%d \",f[i]);puts(\"\");",
            "}",
            "int main(){",
            "//\tfreopen(\"123.txt\",\"r\",stdin);",
            "\tin(n),n=(1<<n),inv2=inv(2);",
            "\tfor(Re i=1;i<=n;++i)in(A[i]);",
            "\tfor(Re i=1;i<=n;++i)in(B[i]);",
            "\tsakura(A,B,n,1),sakura(A,B,n,2),sakura(A,B,n,3);",
            "}",
            ""
        ],
        "description": "插入 多项式 位运算卷积"
    }
}