//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-2.7树状数组",
        "body": [
            "#pragma GCC optimize(2)",
            "#pragma GCC optimize(3,\"Ofast\",\"inline\")",
            "#include<algorithm>",
            "#include<cstdio>",
            "#define Re register int",
            "#define F(i,a,b) for(Re i=a;i<=b;++i)",
            "#define lo(o) lower_bound(b+1,b+m+1,o)-b",
            "#define P(x) if(op[i]==x)",
            "using namespace std;",
            "const int N=1e5+3,inf=2147483647;",
            "int m,T,fu,C[N],a[N],b[N],Q[N],op[N]; ",
            "inline void in(Re &x){",
            "    x=fu=0;char c=getchar();",
            "    while(c<'0'||c>'9')fu|=c=='-',c=getchar();",
            "    while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();",
            "    x=fu?-x:x;",
            "}",
            "inline void add(Re x,Re v){while(x<=m)C[x]+=v,x+=x&-x;}",
            "inline int ask(Re x){",
            "\tRe ans=0;",
            "\twhile(x>0)ans+=C[x],x-=x&-x;",
            "\treturn ans;",
            "}",
            "inline int ask_kth(Re k){",
            "\tRe l=0,r=m;",
            "\twhile(l<r){",
            "\t\tRe mid=l+r>>1;",
            "\t\tif(ask(mid)>=k)r=mid;",
            "\t\telse l=mid+1;",
            "\t}",
            "\treturn b[l];",
            "}",
            "int main(){",
            "\tin(T); ",
            "    F(i,1,T){",
            "    \tin(op[i]),in(Q[i]);",
            "    \tif(op[i]!=4)b[++m]=Q[i];",
            "    }",
            "    sort(b+1,b+m+1),m=unique(b+1,b+m+1)-b-1;",
            "    F(i,1,T){",
            "    \tP(1)add(lo(Q[i]),1);",
            "    \tP(2)add(lo(Q[i]),-1);",
            "\t\tP(3)printf(\"%d\\n\",ask(lo(Q[i])-1)+1);",
            "\t\tP(4)printf(\"%d\\n\",ask_kth(Q[i]));",
            "\t\tP(5)printf(\"%d\\n\",ask_kth(ask(lo(Q[i])-1)));",
            "\t\tP(6)printf(\"%d\\n\",ask_kth(ask(lo(Q[i]))+1));",
            "    }",
            "}",
            ""
        ],
        "description": "插入 普通平衡树"
    }
}