# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
523515 | lukameladze | XOR (IZhO12_xor) | C++14 | 1 ms | 460 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 f first
#define s second
#define pb push_back
#define int long long
using namespace std;
const int N = 3e5 + 5;
int n,x,a[N],pref,idx,sf[N],posri,le,mx,sz,idd,val;
map <int, int> fix[31];
void go(int lee , int rii ){
sz = rii - lee + 1;
if (sz >= mx) {
le = lee;
mx = sz;
}
}
main() {
cin>>n>>x;
for (int i = 1; i <= n; i++) {
cin>>a[i];
}
for (int i = 30; i >= 0; i--) {
if ((1LL<<i)&x) {
idx = i;
break;
}
pref += (1<<i);
}
for (int j = idx; j >= 0; j--) {
fix[j][0] = n + 1;
}
for(int i = n; i >= 1; i--) {
// if (i == 1) cout<<le<<" "<<mx<<endl;
sf[i] = sf[i + 1] ^ a[i];
//if (i == 2) cout<<sf[i]<<" "<<(int)(pref&sf[i])<<endl;
if ((pref&sf[i])) {
le = i;
mx = n - i + 1;
if (!idd) idd = i;
int val = 0;
for (int j = idx; j >= 0; j--) {
if ((1<<j)&sf[i]) val += (1<<j);
fix[j][val] = max(fix[j][val],i);
}
continue;
}
posri = idd - 1;
sz = posri - i + 1;
if (sz >= mx) {
le = i;
mx = sz;
}
int haveto = 0;
for (int j = idx; j >= 0; j--) {
if ((1<<j)&x) {
if (!((1<<j)&sf[i])) haveto += (1<<j);
//if (i == 1) cout<<j<<" " <<haveto<<endl;
continue;
}
if ((1<<j)&sf[i]) {
if (fix[j][haveto]) go(i, fix[j][haveto] - 1);
haveto += (1<<j);
//if (i == 1) cout<<j<<" "<<haveto<<endl;
continue;
}
if (i == 1) cout<<j<<" "<<haveto<<endl;
if (fix[j][haveto + (1<<j)]) go(i, fix[j][haveto + (1<<j)] - 1);
}
//if (i == 1) cout<<haveto<<endl;
if (fix[0][haveto]) {
go(i,fix[0][haveto] - 1);
}
int val = 0;
for (int j = idx; j >= 0; j--) {
if ((1<<j)&sf[i]) val += (1<<j);
fix[j][val] = max(fix[j][val],i);
}
}
cout<<le<<" "<<mx<<endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |