真是6块钱cpu(笑

爆炸入口

踹树练习(汗

对于二进制异或和弹性,我们可以贪心的来做。

瓶颈在于快速贪心。

我们可以维护一个trie树,储存异或前缀和。每次在trie树上贪心的跑。

正向and反向跑一次,就可以了

#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int manx=4e+5;
int t[manx<<5][2],tail;
int l[manx],r[manx],a[manx];
void ins(int val)
{
int now=0;
for(int i=1<<30;i;i>>=1)
{
int c=(val&i) ? 1 : 0 ;
if(!t[now][c]) t[now][c]=++tail;
now=t[now][c];
}
return ;
}//插入
int find(int val)
{
int now=0,ans=0;
for(int i=1<<30;i;i>>=1)
{
int c=(val&i) ? 1 : 0;
if(t[now][c^1]) now=t[now][c^1],ans+=i;//每次根据二进制位,贪心的选择路径
else now=t[now][c];
}
return ans;
}
int main()
{
int n;
scanf("%d",&n);
int now=0;ins(0);
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
now^=a[i];
ins(now);
l[i]=max(l[i-1],find(now));
}//正向扫一遍
memset(t,0,sizeof(t));now=0,tail=0;ins(0);
for(int i=n;i>=1;i--)
{
now^=a[i];
ins(now);
r[i]=max(r[i+1],find(now));//反向和一遍
}
int ans=-0x7fffffff;
for(int i=1;i<=n;i++)
ans=max(l[i]+r[i+1],ans);//这里我们只需要保证不香蕉就可以了(汗
printf("%d",ans);
}

B4260 Codechef REBXOR的更多相关文章

  1. 【BZOJ4260】 Codechef REBXOR 可持久化Trie

    看到异或就去想前缀和(⊙o⊙) 这个就是正反做一遍最大异或和更新答案 最大异或就是很经典的可持久化Trie,从高到低贪心 WA: val&(1<<(base-1))得到的并不直接是 ...

  2. BZOJ 4260: Codechef REBXOR( trie )

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

  3. bzoj 4260: Codechef REBXOR (01 Trie)

    链接: https://www.lydsy.com/JudgeOnline/problem.php?id=4260 题面: 4260: Codechef REBXOR Time Limit: 10 S ...

  4. 【BZOJ4260】Codechef REBXOR (Trie树)

    [BZOJ4260]Codechef REBXOR (Trie树) 题面 BZOJ 题解 两眼题.第一眼不会做,第二眼好简单... 前缀异或和一下,拿\(Trie\)树维护求一个在这个端点以左的最大值 ...

  5. 【BZOJ】4260: Codechef REBXOR【Trie树】【前后缀异或最大】

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

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

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

  7. [Bzoj4260]Codechef REBXOR(trie树)

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

  8. BZOJ4260 Codechef REBXOR 题解

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

  9. BZOJ4260: Codechef REBXOR

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

随机推荐

  1. JS数组去重总结

    方法一: 双层循环,外层循环元素,内层循环时比较值 如果有相同的值则跳过,不相同则push进数组 Array.prototype.distinct = function(){ var arr = th ...

  2. Jquery ValidationEngine 修改验证提示框的位置

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. C# IO流 File.Exists,Directory.Exists, File.Create,Directory.CreateDirectory

    void Start() { CreateDirectory(); CreateFile(); } //平台的路径(封装起来的一个属性,这不是一个方法) public string path { ge ...

  4. pyplot

    错误: 执行 import matplotlib.pyplot 报错 ImportError: No module named _tkinter, please install the python- ...

  5. Building the main Guest Additions module [FAILED]

    虚拟机中的centos7安装vbox的增强工具报错 Building the main Guest Additions module [FAILED] 查看日志发现 unable to find th ...

  6. compile with -fPIC

    在新公司工作第四天,依然要编译FFmpeg,不同的是难度大了,以前遇到什么参数编译不过的,就去掉,因为不是专业做视频的,但是新公司绕不过了. 编译FFmpeg动态库的时候发现链接某些静态库的时候会报错 ...

  7. 使用dtd--属性声明

    <!ATTLIST 元素名 属性名称 属性类型 属性特点> 1.属性类型 类型 含义 CDATA 纯文本 enumerated 枚举类型 ID 以属性的方式唯一标识改元素,必须以字母开头 ...

  8. Swift UI开发初探 (转)

    原文地址:http://www.tairan.com/archives/6600 关于Swift语法,可以参考<Apple Swift编程语言入门教程> 效果如下: 开发环境 Xcode6 ...

  9. echarts自适应宽度

    const myChartContainer = document.getElementById( id ); const resizeMyChartContainer = function () { ...

  10. Vue.js - Day2

    品牌管理案例 添加新品牌 删除品牌 根据条件筛选品牌 1.x 版本中的filterBy指令,在2.x中已经被废除: filterBy - 指令 ​<tr v-for="item in ...