# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1085489 | Sunbae | XOR (IZhO12_xor) | C++17 | 0 ms | 600 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;
const int N = 1e5 + 5;
int a[N], has[32][N], qs[N], f[32];
signed main(){
int n, x, t, mx; scanf("%d %d", &n, &x);
//if(!x){ printf("1 %d", n); return 0;}
t = mx = 31 - __builtin_clz(x);
memset(f, -1, sizeof(f));
for(int i = 0; i<n; ++i){
scanf("%d", a+i);
qs[i] = (i ? qs[i-1] : 0) ^ a[i];
int f_b = 31 - __builtin_clz(a[i]);
mx = max(mx, f_b);
for(int j = 0; j<=f_b; ++j){
if(a[i]>>j&1){
has[j][i] = 1;
if(f[j] == -1) f[j] = i;
}
}
}
int mx_len = 0, min_st = n;
for(int j = t+1; j<=mx; ++j){
int r_s = 0;
for(int i = 0; i<n; ++i){
r_s += has[j][i];
if(r_s&1){
int len = i+1, st = 1;
if(len > mx_len) mx_len = len, min_st = st;
else if(len == mx_len && st < min_st) min_st = st;
}else if(f[j] != -1 && f[j] < i){
int len = i - f[j], st = f[j]+2;
if(len > mx_len) mx_len = len, min_st = st;
else if(len == mx_len && st < min_st) min_st = st;
}
}
}
int r_s = 0;
for(int i = 0, j = t; i<n; ++i){
r_s += has[j][i];
if((r_s&1) && qs[i] >= x){
int len = i+1, st = 1;
if(len > mx_len) mx_len = len, min_st = st;
else if(len == mx_len && st < min_st) min_st = st;
}else if((f[j] != -1) && (f[j] < i) && ((qs[i] ^ qs[f[j]]) >= x)){
int len = i - f[j], st = f[j]+2;
if(len > mx_len) mx_len = len, min_st = st;
else if(len == mx_len && st < min_st) min_st = st;
}
}
printf("%d %d", min_st, mx_len);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |