# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
826362 | hafo | XOR (IZhO12_xor) | C++14 | 142 ms | 59416 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 ull unsigned ll
#define pb push_back
#define pa pair<int, int>
#define pall pair<ll, int>
#define fi first
#define se second
#define TASK "test"
#define Size(x) (int) x.size()
#define all(x) x.begin(), x.end()
using namespace std;
template<typename T1, typename T2> bool mini (T1 &a, T2 b) {if(a > b) a = b; else return 0; return 1;}
template<typename T1, typename T2> bool maxi (T1 &a, T2 b) {if(a < b) a = b; else return 0; return 1;}
const int MOD = 1e9 + 7;
const int LOG = 20;
const int maxn = 25e4 + 7;
const ll oo = 1e9 + 69;
int n, k, f[maxn];
struct node {
node* child[2];
int pos;
node () {
for(int i = 0; i < 2; i++) child[i] = NULL;
pos = oo;
}
};
node* root = new node();
bool getbit(int x, int i) {
return ((x >> i) & 1);
}
struct trie {
void add(int x, int pos) {
node* p = root;
for(int i = 29; i >= 0; i--) {
int nxt = getbit(x, i);
if(p -> child[nxt] == NULL) p -> child[nxt] = new node();
p = p -> child[nxt];
if(p -> pos == oo) p -> pos = pos;
}
}
int get(int x) {
node* p = root;
int ans = oo;
for(int i = 29; i >= 0; i--) {
int nxt = getbit(x, i);
int cur = getbit(k, i);
if(cur == 0) {
if(p -> child[nxt ^ 1] != NULL) mini(ans, p -> child[nxt ^ 1] -> pos);
if(p -> child[nxt] == NULL) return ans;
p = p -> child[nxt];
} else {
if(p -> child[nxt ^ 1] == NULL) return ans;
p = p -> child[nxt ^ 1];
}
}
mini(ans, p -> pos);
return ans;
}
} trie;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//freopen(TASK".inp", "r", stdin);
//freopen(TASK".out", "w", stdout);
cin>>n>>k;
f[0] = 0;
trie.add(0, 0);
int ans = 0, p = 1;
for(int i = 1; i <= n; i++) {
int x;
cin>>x;
f[i] = f[i - 1] ^ x;
int j = trie.get(f[i]);
if(maxi(ans, i - j)) p = j + 1;
trie.add(f[i], i);
}
cout<<p<<" "<<ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |