Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.3 kB
2
Indexable
Never
#include <iostream>
#include <vector>

using namespace std;


struct Node{
    int cnt;
    int go[2];
    
    Node(){
        cnt=0;
        for (int i = 0; i < 26; i++){
            go[i] = -1;
        }
    }
};

vector<Node> trie;
trie.push_back(Node());


void addNumber(long long int x){
    int v = 0;
    for (int i = 30; i>-1; i--){
        int cur = ((x >> i) & 1);
        if (trie[v].go[cur] == -1){
            trie.push_back(Node());
            trie[v].go[cur] = trie.size()-1;
        }
        v = trie[v].go[cur];
    }
    ++trie[v].cnt;
}

void del(long long int x){
    int v=0;
    for (int i = 30; i>-1; i--){
        int cur = ((x >> i) & 1);
        v = trie[v].go[cur];
    }
    --trie[v].cnt;
}

bool find(long long int x){
    int v = 0;
    for (int i = 30; i > -1; i--){
        int cur = ((x >> i) & 1);
        if (trie[v].go[cur] == -1){
            return false;
        }
        v = trie[v].go[cur];
    }
    return trie[v].cnt > 0;
}


int main() {
    long long int q,x;
    string s;
    cin>>q;
    for (int i=0;i<q;i++){
        cin>>s>>x;
        if (s == "+"){
            addNumber(x);
        } else if (s == "-"){
            del(x);
        } else {
            long long int res = max_xor(x);
            cout<<res;
        }
    }
    return 0;
}