Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * author: compounding
- * created: 2024-10-21 17:38:25
- **/
- #include <bits/stdc++.h>
- using namespace std;
- mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
- #define NeedForSpeed \
- ios_base::sync_with_stdio(false); \
- cin.tie(NULL); \
- cout.tie(NULL);
- #define int long long
- #define all(x) (x).begin(), (x).end()
- typedef vector<int> vi;
- typedef vector<bool> vb;
- typedef vector<vi> vvi;
- typedef vector<pair<int, int>> vpi;
- #define f first
- #define s second
- #define endl "\n"
- const int mod = 1000000007;
- int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
- struct node
- {
- node *links[2] = {nullptr, nullptr};
- bool contains(int bit)
- {
- return links[bit] != nullptr;
- }
- node *get(int bit)
- {
- return links[bit];
- }
- void put(int bit, node *nextnode)
- {
- links[bit] = nextnode;
- }
- };
- class trie
- {
- private:
- node *root;
- public:
- trie()
- {
- root = new node();
- }
- void insert(int num)
- {
- node *move = root;
- for (int i = 31; i >= 0; i--)
- {
- int bit = (num >> i) & 1;
- if (!move->contains(bit))
- {
- move->put(bit, new node());
- }
- move = move->get(bit);
- }
- }
- int getmax(int num)
- {
- node *move = root;
- int maxi = 0;
- for (int i = 31; i >= 0; i--)
- {
- int bit = (num >> i) & 1;
- if (move->contains(!bit))
- {
- maxi |= (1 << i);
- move = move->get(!bit);
- }
- else
- {
- move = move->get(bit);
- }
- }
- return maxi;
- }
- };
- void solve()
- {
- int n;
- cin >> n;
- vi v(n);
- int maxixor = 0, prexor = 0;
- trie t;
- t.insert(0);
- for (int i = 0; i < n; i++)
- {
- cin >> v[i];
- prexor ^= v[i];
- maxixor = max(maxixor, t.getmax(prexor));
- t.insert(prexor);
- }
- cout << maxixor << endl;
- }
- signed main()
- {
- NeedForSpeed;
- int t = 1;
- cin >> t;
- while (t--)
- {
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement