fork(28) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. struct trie
  4. {
  5. long long int val;
  6. struct trie *left;
  7. struct trie *right;
  8. };
  9. struct trie *root;
  10. int maxsize = 32;
  11. struct trie *initialise()
  12. {
  13. struct trie *node;
  14. node = new trie();
  15. node->val = -1;
  16. node->left = NULL;
  17. node->right = NULL;
  18. return node;
  19. };
  20. void insert(long long int n)
  21. {
  22. struct trie *node;
  23. node = root;
  24. int i;
  25.  
  26. for(i = maxsize - 1; i >= 0; i--) {
  27. if(n&(1 << i)) {
  28. if(node->right == NULL) {
  29. node->right = initialise();
  30. }
  31. node = node->right;
  32. }
  33. else {
  34. if(node->left == NULL) {
  35. node->left = initialise();
  36. }
  37. node = node->left;
  38. }
  39. }
  40. node->val = n;
  41. }
  42. int query(long long int n)
  43. {
  44. int i;
  45. struct trie *node;
  46. node = root;
  47.  
  48. for(i = maxsize - 1; i >= 0; i--) {
  49. if(n & (1 << i)) {
  50. if(node->left != NULL) {
  51. node = node->left;
  52. }
  53. else {
  54. node = node->right;
  55. }
  56. }
  57. else {
  58. if(node->right != NULL) {
  59. node = node->right;
  60. }
  61. else {
  62. node = node->left;
  63. }
  64. }
  65. }
  66.  
  67. return node->val;
  68. }
  69.  
  70.  
  71.  
  72. int main()
  73. {
  74. long long int n;
  75. long long int a[100005];
  76. int i;
  77. long long int y;
  78. long long int x;
  79. long long int t;
  80. long long int max;
  81. int count;
  82.  
  83.  
  84. scanf("%lld",&t);
  85. while(t--) {
  86. root = initialise();
  87. cin>>n;
  88. max = 0;
  89. count = 0;
  90. for(i = 0; i < n; i++) {
  91. cin>>a[i];
  92.  
  93. }
  94.  
  95.  
  96.  
  97. insert(0);
  98.  
  99. x = 0;
  100.  
  101. for(i = 0; i < n; i++) {
  102. x = x ^ a[i];
  103. insert(x);
  104. y = query(x);
  105. y = y ^ x;
  106. if(y > max) {
  107. max = y;
  108. }
  109. }
  110. cout<<max<<endl;
  111. }
  112.  
  113.  
  114. }
  115.  
Success #stdin #stdout 0s 3940KB
stdin
2  5  3  7  7  7  0  5  3  8  2  6  4
stdout
7
15