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

{
    "[RCOI] XOR  (LCT 计算原树信息)": {
        "prefix": "acm-4.3TLE 30pt",
        "body": [
            "#pragma GCC optimize(3,\"Ofast\",\"inline\")",
            "#include<algorithm>",
            "#include<cstring>",
            "#include<cstdio>",
            "#define Re register int",
            "#define LL long long",
            "using namespace std;",
            "const int N=1e6+3,M=2e6+3;",
            "int n,m,x,y,T,op,HYJ,Ans,root,A[N];",
            "inline void in(Re &x){",
            "    int fu=0;x=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;",
            "}",
            "struct Link_Cut_Tree{",
            "\t#define pl tr[p].ps[0]",
            "\t#define pr tr[p].ps[1]",
            "\t#define pf tr[p].fa",
            "\tint Q[N];",
            "\tstruct QAQ{int fa,si,ans,tag,shi,yuan,ps[2];}tr[N];",
            "\tinline void pushup(Re p){",
            "\t\ttr[p].shi=A[p]^tr[pl].shi^tr[pr].shi;",
            "\t\ttr[p].ans=A[p]^tr[p].si^tr[pl].ans^tr[pr].ans;",
            "\t}",
            "\tinline void updata(Re p){swap(pl,pr),tr[p].tag^=1;}",
            "\tinline void pushdown(Re p){",
            "\t\tif(tr[p].tag){",
            "\t\t\tif(pl)updata(pl);",
            "\t\t\tif(pr)updata(pr);",
            "\t\t\ttr[p].tag=0;",
            "\t\t}",
            "\t}",
            "\tinline int nort(Re p){return tr[pf].ps[0]==p||tr[pf].ps[1]==p;}",
            "\tinline int which(Re p){return tr[pf].ps[1]==p;}",
            "\tinline void connect(Re p,Re fa,Re o){tr[pf=fa].ps[o]=p;}",
            "\tinline void rotate(Re p){",
            "\t\tRe fa=pf,fas=which(p);",
            "\t\tRe pa=tr[fa].fa,pas=which(fa);",
            "\t\tRe x=tr[p].ps[fas^1];",
            "\t\tif(nort(fa))tr[pa].ps[pas]=p;pf=pa;",
            "\t\tconnect(x,fa,fas),connect(fa,p,fas^1);",
            "\t\tpushup(fa),pushup(p);",
            "\t}",
            "\tinline void splay(Re p){",
            "\t\tRe x=p,t=0;Q[++t]=x;",
            "\t\twhile(nort(x))Q[++t]=x=tr[x].fa;",
            "\t\twhile(t)pushdown(Q[t--]);",
            "\t\tfor(Re fa;nort(p);rotate(p))",
            "\t\t\tif(nort(fa=pf))rotate(which(p)==which(fa)?fa:p);",
            "\t}",
            "\tinline int access(Re p){",
            "\t\tRe son=0;",
            "\t\tfor(;p;son=p,p=pf)",
            "\t\t\tsplay(p),tr[p].si^=tr[pr].ans,tr[p].si^=tr[pr=son].ans,pushup(p);",
            "\t\treturn son;",
            "\t}",
            "\tinline void makeroot(Re p){access(p),splay(p),updata(p);}",
            "\tinline int findroot(Re p){",
            "\t\taccess(p),splay(p),pushdown(p);",
            "\t\twhile(pl)pushdown(p=pl);",
            "\t\treturn p;",
            "\t}",
            "\tinline void split(Re x,Re y){makeroot(x),access(y),splay(y);}",
            "\tinline void link(Re x,Re y){",
            "\t\tmakeroot(x);",
            "\t\tif(findroot(y)!=x)tr[tr[x].fa=y].si^=tr[x].ans,pushup(y);",
            "\t}",
            "\tinline int lca(Re x,Re y){access(x);return access(y);}",
            "\t",
            "\tinline int ask_son(Re p){access(p);return tr[pr].ans^tr[p].si^A[p];}",
            "}LCT;",
            "int main(){",
            "//\tfreopen(\"123.txt\",\"r\",stdin);",
            "\tin(n),in(HYJ),in(T),m=n-1,T+=HYJ,root=1;",
            "\tfor(Re i=1;i<=n;++i)in(A[i]);",
            "\twhile(m--)in(x),in(y),LCT.link(x,y);",
            "\tLCT.makeroot(root);",
            "//\tAns=0;for(Re i=1;i<=n;++i)Ans^=LCT.ask_son(i);",
            "//\tprintf(\"%d\\n\",Ans);return 0;",
            "\twhile(T--){",
            "\t\tin(op),in(x);",
            "//\t\tif(op<2)LCT.makeroot(root=x),printf(\"%d\\n\",Ans);",
            "\t\tif(op<2){",
            "\t\t\tLCT.makeroot(root=x);Ans=0;",
            "\t\t\tfor(Re i=1;i<=n;++i)Ans^=LCT.ask_son(i);",
            "\t\t\tprintf(\"%d\\n\",Ans);",
            "\t\t}",
            "\t\telse if(op<3)in(y),LCT.access(x),LCT.splay(x),A[x]=y,LCT.pushup(x);",
            "\t\telse if(op<4)in(y),printf(\"%d\\n\",LCT.lca(x,y));",
            "\t\telse if(op<5)in(y),LCT.split(x,y),printf(\"%d\\n\",LCT.tr[y].shi),LCT.makeroot(root);",
            "\t\telse printf(\"%d\\n\",LCT.ask_son(x));",
            "\t\tLCT.makeroot(root);",
            "\t}",
            "}",
            ""
        ],
        "description": "插入 [RCOI] XOR  (LCT 计算原树信息)"
    }
}