# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1107941 | vjudge1 | XOR (IZhO12_xor) | C++17 | 1 ms | 336 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |