//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.1Editor",
        "body": [
            "#include<algorithm>",
            "#include<iostream>",
            "#include<cstdio>",
            "using namespace std;",
            "const int N=1e6+5;",
            "int m,x,tl,tr,L[N],R[N],f[N],s[N];char a;",
            "int main(){",
            "    while(scanf(\"%d\",&m)!=EOF){",
            "        s[0]=0;f[0]=-0xfffffff;tl=tr=0;",
            "        while(m--){",
            "            cin>>a;",
            "            if(a=='I'){",
            "                scanf(\"%d\",&x);",
            "                L[++tl]=x;",
            "                f[tl]=max(f[tl-1],s[tl]=s[tl-1]+x);",
            "            }",
            "            else if(a=='R'){",
            "                if(tr){",
            "                    x=L[++tl]=R[tr--];",
            "                    f[tl]=max(f[tl-1],s[tl]=s[tl-1]+x);",
            "                }",
            "            }",
            "            else if(a=='Q')scanf(\"%d\",&x),printf(\"%d\\n\",f[x]);",
            "            else if(a=='L'){if(tl)R[++tr]=L[tl--];}",
            "            else if(tl)tl--;",
            "        }",
            "    }",
            "}",
            ""
        ],
        "description": "插入 对顶栈"
    }
}