当前位置: 代码迷 >> 综合 >> bzoj4260: Codechef REBXOR
  详细解决方案

bzoj4260: Codechef REBXOR

热度:93   发布时间:2023-10-29 12:22:48.0

题意

题目自己看【不负责】

题解

异或的话上次知道了新武器—–可持久化tir
这题也是。。
对于这道题,就DP两次
正着一次,反着一次就好了

我的代码拍的时候和标程差不多快。。
然后TLE了。。。
然后FYC10s卡时过。。放一个他的代码吧

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#define LL long long
const int N=400005;
using namespace std;
struct trnode{int c,a[2];
}tr[35*N];int root[N],tot=0;
LL read()
{LL x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){
   if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){
   x=x*10+ch-'0';ch=getchar();}return x*f;
}
void add(int &x,int froot,LL k,int num)
{x=++tot;tr[x]=tr[froot];tr[x].c++;if(num==-1) return;LL c=(k&(1LL<<num));c=(c!=0);add(tr[x].a[c],tr[froot].a[c],k,num-1);
}
LL solve(int lroot,int rroot,LL k,int num)
{if(num==-1) return 0;LL c=(k&(1LL<<num));c=(c!=0);c^=1;int lrc=tr[tr[lroot].a[c]].c,rrc=tr[tr[rroot].a[c]].c;if(lrc==rrc) c^=1;return (c<<num)+solve(tr[lroot].a[c],tr[rroot].a[c],k,num-1);
}
int n;
LL a[N],sum1[N],sum2[N];
int main()
{n=read();a[0]=0;add(root[1],root[0],0,33);for(int i=1;i<=n;i++){a[i+1]=read();a[i+1]^=a[i];add(root[i+1],root[i],a[i+1],33);}sum1[0]=-1;sum2[n+2]=-1;for(int i=2;i<=n+1;i++) sum1[i]=max(sum1[i-1],solve(root[0],root[i],a[i],33)^a[i]);for(int i=n+1;i>=2;i--) sum2[i]=max(sum2[i+1],solve(root[i-2],root[n+1],a[i],33)^a[i]);LL ans=-1;for(int i=2;i<=n;i++) ans=max(ans,sum1[i]+sum2[i+1]);printf("%lld",ans);
}