//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.2optimize",
        "body": [
            "#pragma GCC optimize(3,\"Ofast\",\"inline\")",
            "#pragma GCC optimize(2)",
            "#include<cstdio>",
            "#define LL long long",
            "const int N=1e6+5,P=998244353;",
            "int n,i,ans,a[N],g[N],C[N],jc[N]={1};",
            "inline void add(int x){while(x<=n)++C[x],x+=x&-x;}",
            "inline int ask(int x){",
            "\tint ans=0;",
            "\twhile(x)ans+=C[x],x-=x&-x;",
            "\treturn ans;",
            "}",
            "int main(){",
            "\tscanf(\"%d\",&n);",
            "\tfor(i=1;i<=n;++i)scanf(\"%d\",&a[i]);",
            "\tfor(i=n;i;--i)g[i]=ask(a[i]-1),add(a[i]);",
            "\tfor(i=1;i<=n;++i)jc[i]=(LL)jc[i-1]*i%P;",
            "\tfor(i=1;i<=n;++i)(ans+=(LL)g[i]*jc[n-i]%P)%=P;",
            "\tprintf(\"%d\",ans+1);",
            "}",
            ""
        ],
        "description": "插入 康托展开"
    }
}