//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.4FFT",
        "body": [
            "#include<algorithm>",
            "#include<cstdio>",
            "#include<cmath>",
            "#define LD double",
            "#define LL long long",
            "#define Re register int",
            "using namespace std;",
            "const int N=2097152+3;",
            "const LD Pi=acos(-1);",
            "int n,m,tr[N];",
            "inline void in(Re &x){",
            "\tRe fu=0;x=0;char ch=getchar();",
            "\twhile(ch<'0'||ch>'9')fu|=ch=='-',ch=getchar();",
            "\twhile(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();",
            "\tx=fu?-x:x;",
            "}",
            "struct CP{",
            "\tLD x,y;CP(LD X=0,LD Y=0){x=X,y=Y;}",
            "\tinline CP operator+(const CP &O)const{return CP(x+O.x,y+O.y);}",
            "\tinline CP operator-(const CP &O)const{return CP(x-O.x,y-O.y);}",
            "\tinline CP operator*(const CP &O)const{return CP(x*O.x-y*O.y,x*O.y+y*O.x);}//(ac-bd,bc+ad)",
            "\tinline CP operator/(const CP &O)const{",
            "\t\tLD tmp=O.x*O.x+O.y*O.y;//tmp=c^2+d^2",
            "\t\treturn CP((x*O.x+y*O.y)/tmp,(y*O.x-x*O.y)/tmp);//( (ac+bd)/tmp,(bc-ad)/tmp )",
            "\t}",
            "\tinline CP operator*=(const CP &O){return *this=*this*O;}",
            "}f[N],g[N];",
            "inline void FFT(CP *f,Re n,Re op){//op=0:DFT, op=1:IDFT",
            "\tfor(Re i=0;i<n;++i)if(i<tr[i])swap(f[i],f[tr[i]]);",
            "\tfor(Re p=2;p<=n;p<<=1){",
            "\t\tRe len=p>>1;CP w1(cos(2*Pi/p),sin(2*Pi/p));",
            "\t\tif(op)w1.y*=-1;",
            "\t\tfor(Re st=0;st<n;st+=p){",
            "\t\t\tCP base(1,0);",
            "\t\t\tfor(Re i=st;i<=st+len-1;++i){",
            "\t\t\t\tCP tmp=base*f[len+i];",
            "\t\t\t\tf[len+i]=f[i]-tmp,f[i]=f[i]+tmp,base*=w1;",
            "\t\t\t}",
            "\t\t}",
            "\t}",
            "}",
            "inline void times(CP *f,Re n,CP *g,Re m){",
            "\tfor(m+=n,n=1;n<=m;n<<=1);",
            "\tfor(Re i=1;i<n;++i)tr[i]=(tr[i>>1]>>1)|((i&1)?n>>1:0);",
            "\tFFT(f,n,0),FFT(g,n,0);",
            "\tfor(Re i=0;i<n;++i)f[i]*=g[i];",
            "\tFFT(f,n,1);",
            "\tfor(Re i=0;i<=m;++i)f[i].x/=n;",
            "}",
            "int main(){",
            "//\tfreopen(\"123.txt\",\"r\",stdin);",
            "\tin(n),in(m);",
            "\tfor(Re i=0;i<=n;++i)scanf(\"%lf\",&f[i].x);",
            "\tfor(Re i=0;i<=m;++i)scanf(\"%lf\",&g[i].x);",
            "\ttimes(f,n,g,m);",
            "\tfor(Re i=0;i<=n+m;++i)printf(\"%d \",(int)(f[i].x+0.5));",
            "}",
            ""
        ],
        "description": "插入 多项式 乘法"
    }
}