Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void solveD()
- {
- int n, ans = 0;
- cin >> n;
- vector<vector<int>> a(1, vector<int>(n)), b(1, vector<int>(n));
- for (auto& ai : a[0])
- cin >> ai;
- for (auto& bi : b[0])
- cin >> bi;
- for (int bit = 29; bit >= 0; bit--)
- {
- bool cansep = true;
- for (int pi = 0; pi < a.size() && cansep; pi++)
- {
- int cnt = 0;
- for (auto& ai : a[pi])
- cnt += (ai & (1 << bit)) >> bit;
- for (auto& bi : b[pi])
- cnt += (bi & (1 << bit)) >> bit;
- if (cnt != a[pi].size())
- cansep = false;
- }
- if (cansep)
- {
- ans += (1 << bit);
- vector<vector<int>> new_a(a.size() * 2), new_b(a.size() * 2);
- for (int pi = 0; pi < a.size(); pi++)
- {
- int cnt = 0;
- for (auto& ai : a[pi])
- if (ai & (1 << bit))
- new_a[pi * 2].push_back(ai);
- else
- new_a[pi * 2 + 1].push_back(ai);
- for (auto& bi : b[pi])
- if (bi & (1 << bit))
- new_b[pi * 2 + 1].push_back(bi);
- else
- new_b[pi * 2].push_back(bi);
- }
- a.clear();
- b.clear();
- for (int pi = 0; pi < new_a.size(); pi++)
- {
- if (new_a[pi].size())
- {
- a.push_back(vector<int>());
- swap(a.back(), new_a[pi]);
- b.push_back(vector<int>());
- swap(b.back(), new_b[pi]);
- }
- }
- }
- }
- cout << ans << endl;
- }
- int main() {
- #ifdef DEBUG
- freopen("input.in", "r", stdin);
- freopen("output.out", "w", stdout);
- #endif
- int t;
- cin >> t;
- while (t--)
- solveD();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement