Trie模板题。求出每个前缀和后缀的最大异或和区间,枚举断点就可。不知为何跑得飞快。

 #include<cstdio>
#include<cstring>
#include<algorithm>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
using namespace std; const int N=,M=N*;
int n,nd,x,ans,a[N],pre[N],suf[N],ch[M][]; void ins(int k){
int x=;
for (int i=; ~i; i--){
if (!ch[x][(k>>i)&]) ch[x][(k>>i)&]=++nd;
x=ch[x][(k>>i)&];
}
} int que(int k){
int x=,res=;
for (int i=; ~i; i--)
if (ch[x][!((k>>i)&)]) res|=<<i,x=ch[x][!((k>>)&)];
else x=ch[x][(k>>i)&];
return res;
} int main(){
freopen("bzoj4260.in","r",stdin);
freopen("bzoj4260.out","w",stdout);
scanf("%d",&n); nd=; ins();
rep(i,,n) scanf("%d",&a[i]);
rep(i,,n-) x^=a[i],pre[i]=max(pre[i-],que(x)),ins(x);
memset(ch,,sizeof(ch)); nd=; ins(); x=;
for (int i=n; i>; i--) x^=a[i],suf[i]=max(suf[i+],que(x)),ins(x);
rep(i,,n-) ans=max(ans,pre[i]+suf[i+]);
printf("%d\n",ans);
return ;
}

[BZOJ4260]Codechef REBXOR(Trie)的更多相关文章

  1. 【BZOJ4260】Codechef REBXOR Trie树+贪心

    [BZOJ4260]Codechef REBXOR Description Input 输入数据的第一行包含一个整数N,表示数组中的元素个数. 第二行包含N个整数A1,A2,…,AN. Output ...

  2. [Bzoj4260]Codechef REBXOR(trie树)

    4260: Codechef REBXOR Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 1534  Solved: 669[Submit][Stat ...

  3. BZOJ 4260: Codechef REBXOR( trie )

    求出前缀和, 那么以第x个元素结尾的最大异或值是max(sumx^sump)(1≤p<x), 用trie加速. 后缀同理, 然后扫一遍就OK了.时间复杂度O(31N) ------------- ...

  4. BZOJ4260 Codechef REBXOR(trie)

    用trie求出前缀最大区间异或和.后缀最大区间异或和即可.注意空间是nlog的. #include<iostream> #include<cstdio> #include< ...

  5. 【bzoj4260】Codechef REBXOR Trie树

    题目描述 输入 输入数据的第一行包含一个整数N,表示数组中的元素个数. 第二行包含N个整数A1,A2,…,AN. 输出 输出一行包含给定表达式可能的最大值. 样例输入 5 1 2 3 1 2 样例输出 ...

  6. 【bzoj4260】 Codechef REBXOR trie树

    Input 输入数据的第一行包含一个整数N,表示数组中的元素个数. 第二行包含N个整数A1,A2,…,AN.     Output 输出一行包含给定表达式可能的最大值.   Sample Input ...

  7. BZOJ4260 Codechef REBXOR 题解

    题目大意: 有一个长度为n的序列,求1≤l1≤r1<l2≤r2≤n使得(⊕r1i=l1ai)+(⊕r2i=l2ai)最大,输出这个最大值. 思路: 用Trie求出前缀异或和以及后缀异或和,再求出 ...

  8. BZOJ4260: Codechef REBXOR

    Description Input 输入数据的第一行包含一个整数N,表示数组中的元素个数. 第二行包含N个整数A1,A2,…,AN.     Output 输出一行包含给定表达式可能的最大值.   S ...

  9. BZOJ4260: Codechef REBXOR (01Tire树)

    题意 题目链接 Sol 首先维护出前缀xor和后缀xor 对每个位置的元素插入到Trie树里面,每次找到和该前缀xor起来最大的元素 正反各做一遍,取最大. 记得要开log倍空间qwq.. #incl ...

随机推荐

  1. angular 开发之proxy

    创建proxy配置文件proxy.conf.json 内容如下  {   "/api/*": { "target": "https://abc.com ...

  2. 【BZOJ】2820: YY的GCD

    [题意]给定N, M,求1<=x<=N, 1<=y<=M且gcd(x, y)为质数的(x, y)有多少对.T<=10^4,N,M<=10^7. [算法]数论(莫比乌 ...

  3. About configuration center of Apollo

    A comparison among different configuration management tools Use of Apollo configuration management p ...

  4. jquery实现简单轮播

    先上简单的html代码 <!DOCTYPE HTML> <html> <head> <link rel="stylesheet" type ...

  5. java版云笔记(八)之关联映射

    Mybatis关联映射 通过数据库对象之间的关联关系,反映到到实体对象之间的引用. 加载多个表中的关联数据,封装到我们的实体对象中. 当业务对数据库进行关联查询. 关联 <association ...

  6. SVM资料

    解释SMO算法比较好的文档 http://wenku.baidu.com/view/aeba21be960590c69ec3769e.html 参考博客: http://myjuno.blogbus. ...

  7. SuSE Linux Supervisor的安装与使用案例

      建议使用 root 管理员账户操作 1.安装工具 1.apache 2..Net Core(dotnet-sdk-2.0) 3.Supervisor(进程管理工具,目的是服务器一开机就启动服务器 ...

  8. CGIC函数说明

    CGIC函数说明 参考cgic函数说明_Embedded Resources Library Online (C)郝博士 cgiFormResultType cgiFormString( char * ...

  9. Shell语言系列之一:文件处理

    前言 &nbsp 标准输入/输出可能是软件工具设计原则里最基本的观念了.有很多UNIX程序都遵循这一设计历练.默认情况下,他们会读取标准输入,写入标准输出,并将错误信息传递给标准错误输出. & ...

  10. [MySQL]You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column

    执行update语句,出现问题: 问题描述: You are using safe update mode and you tried to update a table without a WHER ...