01字典树数组版

int ch[maxn * 32][2];
int tol;
int val[maxn *32];
void inint(){
    ch[0][0] = ch[0][1] = 0;
    tol = 1;
}
void insert(ll x){
    int u = 0, v, i;
    for(i = 32; i >= 0; i--){
        v = (x>>i) & 1;
        if(!ch[u][v]){
            ch[tol][0] = ch[tol][1] = 0;
            val[tol] = 0;
            ch[u][v] = tol++;

        }
            u = ch[u][v];
    }
    val[u] = x;
}
int query(ll x){
    int u = 0, v, i;
    for(i = 32; i >= 0; i--){
        v = (x>>i) &1;
        if(ch[u][v^1]) u = ch[u][v^1];
        else u = ch[u][v];
    }
    return val[u];
}

你可能感兴趣的:(01字典树数组版)