//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.11可并堆",
        "body": [
            "#include<algorithm>",
            "#include<cstring>",
            "#include<cstdio>",
            "#include<cmath>",
            "#define LL long long",
            "#define Re register int",
            "using namespace std;",
            "const int N=1e5+5;",
            "int n,x,y,T,op,A[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 Leftist_Tree{",
            "\tint fa[N],pl[N],pr[N],dis[N];",
            "\tinline int merge(Re x,Re y){",
            "\t\tif(!x||!y)return x+y;",
            "\t\tif(A[x]>A[y]||(A[x]==A[y]&&x>y))swap(x,y);",
            "\t\tpr[x]=merge(pr[x],y);",
            "\t\tif(dis[pl[x]]<dis[pr[x]])swap(pl[x],pr[x]);",
            "\t\tdis[x]=dis[pr[x]]+1;",
            "\t\tif(pl[x])fa[pl[x]]=x;",
            "\t\tif(pr[x])fa[pr[x]]=x;",
            "\t\treturn x;",
            "\t}",
            "\tinline int top(Re x){return fa[x]==x?x:fa[x]=top(fa[x]);}",
            "\tinline void pop(Re x){",
            "\t\tA[x]=-1,fa[pl[x]]=pl[x],fa[pr[x]]=pr[x];",
            "\t\tfa[x]=merge(pl[x],pr[x]),pl[x]=pr[x]=0;",
            "\t}",
            "}T1;",
            "int main(){",
            "//\tfreopen(\"123.txt\",\"r\",stdin);",
            "\tin(n),in(T);",
            "\tfor(Re i=1;i<=n;++i)in(A[i]),T1.fa[i]=i;",
            "\twhile(T--){",
            "\t\tin(op),in(x);",
            "\t\tif(op&1){",
            "\t\t\tin(y);",
            "\t\t\tif(A[x]!=-1&&A[y]!=-1){",
            "\t\t\t\tx=T1.top(x),y=T1.top(y);",
            "\t\t\t\tif(x!=y)T1.merge(x,y);",
            "\t\t\t}",
            "\t\t}",
            "\t\telse if(A[x]==-1)puts(\"-1\");",
            "\t\telse printf(\"%d\\n\",A[T1.top(x)]),T1.pop(T1.top(x));",
            "\t}",
            "}",
            ""
        ],
        "description": "插入 左偏树"
    }
}