# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
91812 | SamAnd | XOR (IZhO12_xor) | C++17 | 1840 ms | 15992 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 <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
using namespace std;
const int N=1000000,M=31;
int a[N], p[N], n;
int x, y, b, t;
int xx[M], yy[M];
int ansx=0,ansy=-1;
void erk()
{
int i = 0;
while(x || i < 30)
{
xx[i] = x % 2;
++i;
x /= 2;
}
reverse(xx, xx + M);
}
void ubd()
{
map<int,int> mp;
for(int i=0;i<=n;++i)
{
int mn = p[i]&b^y&b;
if(mp.find(mn)!=mp.end() && (i-mp[mn]>ansy-ansx || (i-mp[mn]==ansy-ansx && i<ansx)))
{
ansx=mp[mn];
ansy=i;
}
if(mp.find(p[i]&b)==mp.end())
mp[p[i]&b]=i;
}
///
}
int main()
{
//freopen("c.in","r",stdin);
//freopen("c.out","w",stdout);
//in
scanf("%d%d",&n,&x);
for(int i=1;i<=n;++i)
scanf("%d",&a[i]);
for(int i=1;i<=n;++i)
p[i]=p[i-1]^a[i];
////
t=1;
for(int i=0;i<M;++i)
t*=2;
--t;
erk();
////
bool z=false;
for(int i=0;i<M;++i)
{
b|=(1<<(M-1-i));
if(xx[i]==0)
{
yy[i]=1;
y|=(1<<(M-1-i));
ubd();
yy[i]=0;
y^=(1<<(M-1-i));
}
else
{
z=true;
yy[i]=1;
y|=(1<<(M-1-i));
}
if(!z)
b^=(1<<(M-1-i));
}
ubd();
////
cout<<ansx+1<<' '<<(ansy-(ansx+1)+1)<<endl;
// system("pause");
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |