# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
319635 | jovan_b | XOR (IZhO12_xor) | C++17 | 137 ms | 21348 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>
using namespace std;
typedef long long ll;
typedef long double ld;
int trie[2000005];
int sled[2000005][2];
int mn[2000005];
int cnt;
int x;
void trieadd(int v, int ind){
int node = 0;
mn[node] = min(mn[node], ind);
for(int i=29; i>=0; i--){
if(v&(1<<i)){
if(!sled[node][1]) sled[node][1] = ++cnt;
node = sled[node][1];
}
else{
if(!sled[node][0]) sled[node][0] = ++cnt;
node = sled[node][0];
}
mn[node] = min(mn[node], ind);
}
}
int query(int v){
int node = 0;
int res = 1000000;
for(int i=29; i>=0; i--){
if(x&(1<<i)){
int t = 1;
if(v&(1<<i)) t = 0;
if(!sled[node][t]) break;
node = sled[node][t];
}
else{
int t = 1;
if(v&(1<<i)) t = 0;
if(sled[node][t]){
res = min(res, mn[sled[node][t]]);
}
if(!sled[node][1^t]) break;
node = sled[node][1^t];
}
}
return res;
}
int main(){
ios_base::sync_with_stdio(false), cin.tie(0);
cout.precision(10);
cout << fixed;
int n;
cin >> n >> x;
if(x == 0){
cout << 1 << " " << n << "\n";
return 0;
}
for(int i=0; i<=1000000; i++) mn[i] = 1000000;
x--;
int xx = 0;
trieadd(0, 0);
int resi = 0, res = 0;
for(int i=1; i<=n; i++){
int a;
cin >> a;
xx ^= a;
int g = query(xx);
if(i-g > res){
resi = g+1;
res = i-g;
}
trieadd(xx, i);
}
cout << resi << " " << res << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |