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

{
    "可持久化Trie树": {
        "prefix": "acm-6.3最大异或和",
        "body": [
            "#include<algorithm>",
            "#include<cstring>",
            "#include<cstdio>",
            "#include<cmath>",
            "#define LL long long",
            "#define Re register int",
            "using namespace std;",
            "const int N=6e5+5,logN=24;",
            "int n,x,y,z,T,A[N],pt[N];char op;",
            "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 Trie{",
            "\tint O,cnt[N*(logN+2)],tr[N*(logN+2)][2];",
            "\tinline void insert(Re p,Re q,Re o,Re x){",
            "\t\tif(o<0)return;Re i=(x>>o)&1;",
            "\t\ttr[p][i]=++O,tr[p][i^1]=tr[q][i^1];",
            "\t\tcnt[tr[p][i]]=cnt[tr[q][i]]+1;",
            "\t\tinsert(tr[p][i],tr[q][i],o-1,x);",
            "\t}",
            "\tinline int ask(Re p,Re q,Re o,Re x){",
            "\t\tif(o<0)return 0;Re i=(x>>o)&1;",
            "\t\tif(cnt[tr[q][i^1]]>cnt[tr[p][i^1]])return (1<<o)+ask(tr[p][i^1],tr[q][i^1],o-1,x);",
            "\t\telse return ask(tr[p][i],tr[q][i],o-1,x);",
            "\t}",
            "}T1;",
            "int main(){",
            "//\tfreopen(\"123.txt\",\"r\",stdin);",
            "\tin(n),in(T);",
            "\tfor(Re i=1;i<=n;++i)in(A[i]),A[i]^=A[i-1],T1.insert(pt[i]=++T1.O,pt[i-1],logN,A[i]);",
            "\tT1.insert(pt[0]=++T1.O,0,logN,0);",
            "\twhile(T--){",
            "\t\tscanf(\" %c\",&op),in(x);",
            "\t\tif(op=='A')++n,A[n]=A[n-1]^x,T1.insert(pt[n]=++T1.O,pt[n-1],logN,A[n]);",
            "\t\telse in(y),in(z),--x,--y,printf(\"%d\\n\",T1.ask(x?pt[x-1]:0,pt[y],logN,z^A[n]));",
            "\t}",
            "}",
            ""
        ],
        "description": "插入 可持久化Trie树"
    }
}