//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-1.5optimize",
        "body": [
            "#pragma GCC optimize(3,\"Ofast\",\"inline\")",
            "#pragma GCC optimize(2)",
            "#include<cstdio>",
            "#define Re register int",
            "const int N=5e5+3;",
            "int fu,n,s[N],b[N];long long gs;char ch;",
            "inline void in(int &x){",
            "\tfu=x=0;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;",
            "}",
            "void merge(Re L,Re mid,Re R){",
            "    Re i=L,j=mid+1,w=L;",
            "    while(i<=mid&&j<=R){",
            "        if(s[i]<=s[j])b[w++]=s[i++];",
            "        else b[w++]=s[j++],gs+=mid-i+1;",
            "    }",
            "    for(;i<=mid;i++)b[w++]=s[i];",
            "    for(;j<=R;j++)b[w++]=s[j];",
            "    for(i=L;i<=R;i++)s[i]=b[i];",
            "}",
            "inline void Sort(Re L,Re R){",
            "    if(L<R){",
            "        Re mid=L+R>>1;",
            "        Sort(L,mid),Sort(mid+1,R);",
            "        merge(L,mid,R);",
            "    }",
            "}",
            "int main(){",
            "    in(n);",
            "    for(Re i=1;i<=n;i++)in(s[i]);",
            "    Sort(1,n);",
            "    for(Re i=1;i<=n;i++)printf(\"%d \",s[i]); ",
            "}",
            ""
        ],
        "description": "插入 归并排序"
    }
}