Title Address
Test instructions: tells you a sequence, and then gives you m operations, each operation is to put this sequence XOR x, and then the smallest number that does not appear in this sequence.
Idea: Because the definition of XOR is to turn into a 2 binary form, each bit the same as 0, the difference is 1. In this way we can convert the number into binary into the dictionary tree (binary tree, left 0 to the right 1), XOR is to turn the XOR number into binary form, the bit is 1 to flip the dictionary tree node two child nodes just fine. When the query is always looking to the left, until the following number is full to go to the right sub-tree to find (this can not understand the structure of my code to see the comments), the final result is the smallest number. (Note that the maximum number is 3*10^5 so the 20 layer is good, there will not be more than 20 layers of the situation, and then turn into a binary after the previous 0, so it is better to store the value in the dictionary tree)
#include <iostream> #include <cstring> #include <string> #include <queue> #include <vector > #include <map> #include <set> #include <stack> #include <cmath> #include <cstdio> #inc Lude <algorithm> #include <iomanip> #define N 300010 #define M 2//number of child nodes per node #define LL __int64 #define INF 0 X3F3F3F3F #define Lson l,mid,ans<<1 #define Rson mid+1,r,ans<<1|1 #define GETMID (l+r) >>1 #define Movel
Ans<<1 #define Mover ans<<1|1 using namespace std;
Const LL mod = 1000000007;
int n, m;
int num[n];
struct Node {int cnt, RES;//CNT is the number of it is below it, that is, when the query to determine whether the numbers are already completely there, RES is record XOR value, want to when with a delay marker time node *next[m];
void Init () {for (int i = 0; i < M; i++) {next[i] = NULL;
} res = 0;
CNT = 0;
}
};
void Push_down (node *p, int d) {//XOR invert left and right child, passing down for (int i = 0; i < M; i++) {if (P->next[i]) { P->next[i]->res ^= p->res;
}} if ((P->res >> D) & 1) {swap (p->next[0], p->next[1]);
} p->res = 0;
} struct Trie {Void Insert (node *root, int num) {//need to customize node *p = root;
p->cnt++;
for (int i = ~i; i--) {int k = (num >> i) & 1;
if (p->next[k] = = NULL) {P->next[k] = new node;
P->next[k]->init ();
} p = p->next[k];
p->cnt++;
}} int solve (node *root) {node *p = root;
int ans = 0;
for (int i = ~i; i--) {Push_down (P, i); if (p->next[0] = = NULL | | (p->next[0]! = null&&p->next[0]->cnt! = (1 << i)))
{p = p->next[0];
} else {p = p->next[1];
Ans + = 1 << i;
} if (p = = NULL) return ans;
} } Void Free (node *p) {for (int i = 0; i < M; i++) if (P->next[i]) free (p->next[i]);
Delete p;
}}tree;
int main () {Cin.sync_with_stdio (false);
Node *root;
while (CIN >> n >> m) {for (int i = 0; i < n; i++) {cin >> num[i];
} sort (num, num + N);
n = unique (num, num + n)-num;
root = new node;
Root->init ();
for (int i = 0; i < n; i++) {Tree.insert (root, num[i]);
} for (int i = 0; i < m; i++) {int k;
Cin >> K;
Root->res ^= K;
cout << tree.solve (root) << Endl; } tree.
Free (root);
} return 0; }