//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 的格式要求是 "插入 [该代码片段的中文名]"

{
    "左偏树-P3377": {
        "prefix": "acm-2.13luogu-p3377",
        "body": [
            "typedef pair<int,int> P;  // 存储键值对，通常用于比较优先级",
            "struct Node {",
            "    int l, r, d;  // l:左孩子, r:右孩子, d:距离（null路径长度）",
            "    P v;          // 存储的值（键值对）",
            "    Node(){}",
            "    Node(int _l,int _r,int _d,P _v){l=_l,r=_r,d=_d,v=_v;}",
            "} T[N];  // 数组存储所有节点",
            "int merge(int a,int b){",
            "    if(!a) return b;",
            "    if(!b) return a;",
            "    if(T[a].v < T[b].v)swap(a,b);",
            "    T[a].r = merge(T[a].r,b);",
            "    if(T[T[a].l].d < T[T[a].r].d)swap(T[a].l,T[a].r);",
            "    T[a].d=T[a].r ? T[T[a].r].d+1:0;",
            "    return a;",
            "}",
            "int pop(int a){",
            "    int l = T[a].l,r=T[a].r;",
            "    T[a].l=T[a].r=T[a].d=0;",
            "    return merge(l,r);",
            "}"
        ],
        "description": "插入 左偏树-P3377"
    }
}