AcWing 1414. 牛异或
作者:
闪回
,
2024-03-29 20:29:52
,
所有人可见
,
阅读 2
模板题acwing143最大异或对 -> acwing1414牛异或(记录下标) -> acwing3485最大异或和(删除操作+滑动窗口)
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N = (1e5+10) * 20,M = 1e5+10;
int son[N][2],idx;
int n;
int a[N],s[N];
int Hash[N];
void insert(int x,int id)
{
int p = 0;
for(int i = 30;i>=0;i--)
{
int u = (x>>i)&1;
if(!son[p][u])son[p][u] = ++idx;
p = son[p][u];
}
Hash[p] = id;
}
int query(int x)
{
int p = 0;
for(int i = 30;i>=0;i--)
{
int u = (x>>i)&1;
if(son[p][!u])p = son[p][!u];
else p = son[p][u];
}
return Hash[p];
}
int main()
{
cin>>n;
for(int i = 1;i<=n;i++)
{
cin>>a[i];
s[i] = s[i-1] ^ a[i];
}
int res = -1,l = 0,r = 0;
insert(s[0],0);
for(int i = 1;i<=n;i++)
{
int t = query(s[i]);
if((s[t] ^ s[i]) > res)
{
res = s[t] ^ s[i];
l = t + 1;
r = i;
}
insert(s[i],i);
}
cout<<res<<" "<<l<<" "<<r<<endl;
return 0;
}