제출 #1107941

#제출 시각아이디문제언어결과실행 시간메모리
1107941vjudge1XOR (IZhO12_xor)C++17
0 / 100
1 ms336 KiB
#include <bits/stdc++.h> #define ll long long #define deb(x) cout << #x << " : " << x << endl; #define take_input(a) \ for (auto &x : a) \ cin >> x; #define _output(a) \ for (auto &x : a) \ cout << x << " "; \ cout << endl; #define srt(a) sort(a.begin(), a.end()) #define nl "\n" using namespace std; struct Node { Node *childrens[2]; int indx; Node(int i) : indx(i) {}; bool containsKey(int i) { return childrens[i] != NULL; } Node *get(int i) { return childrens[i]; }; void put(int i, Node *node) { childrens[i] = node; }; }; class Trie { private: Node *root; public: Trie() { root = new Node(0); } void insert(int num, int indx) { Node *node = root; for (int i = 30; i >= 0; i--) { bool bit = (num >> i) & 1 ? true : false; if (!node->containsKey(bit)) { node->put(bit, new Node(indx)); } node = node->get(bit); } } pair<int, int> query(int num, int k, int idx) { int start = -1; int len = 0; Node *node = root; for (int i = 30; i >= 0; i--) { bool bit = (num >> i) & 1 ? true : false; bool Kbit = (k >> i) & 1 ? true : false; if (node->containsKey(1 - bit)) { if (!Kbit) { int sz = idx - node->childrens[1 - bit]->indx; if (len < sz) { start = node->childrens[1 - bit]->indx + 1; len = sz; } return {start, len}; } node = node->get(1 - bit); } else { if (Kbit) { return {start, Kbit}; } else node = node->get(bit); } } return {start, len}; } }; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int T = 1; // cin >> T; while (T--) { int n, k; cin >> n >> k; int xr = 0; pair<int, int> ans{-1, -1}; Trie t; t.insert(0, 0); for (int i = 1; i <= n; i++) { int temp; cin >> temp; xr = xr ^ temp; pair<int, int> p = t.query(xr, k, i); if (p.second > ans.second) ans = p; t.insert(xr, i); } cout << ans.first << " " << ans.second << endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...