题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4260

用 Trie 树可以找出前缀异或的最大值和后缀异或的最大值,拼起来即可;

注意要先加入一个0,表示区间左端点在 0 或右端点在 n+1;

竟然1A了!感动。

——然后发现3个月前做过!!!... https://www.cnblogs.com/Zinn/p/9301536.html

代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int const xn=4e5+,mx=;
int n,cnt,a[xn],pr[xn],sc[xn],c[xn*mx][],bin[mx+];
int rd()
{
int ret=,f=; char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=; ch=getchar();}
while(ch>=''&&ch<='')ret=(ret<<)+(ret<<)+ch-'',ch=getchar();
return f?ret:-ret;
}
void init()
{
bin[]=;
for(int i=;i<=mx;i++)bin[i]=bin[i-]*;
}
void add(int x)
{
int nw=;
for(int i=mx;i>=;i--)
{
bool d=(x&bin[i]);
if(!c[nw][d])c[nw][d]=++cnt; nw=c[nw][d];
}
}
int query(int x)
{
int nw=,ret=;
for(int i=mx;i>=;i--)
{
bool d=!(x&bin[i]);
if(c[nw][d])nw=c[nw][d],ret+=bin[i];
else nw=c[nw][!d];
}
return ret;
}
int main()
{
n=rd(); init(); add();//
for(int i=,x,s=;i<=n;i++)
{
x=rd(); a[i]=x; s^=x;
pr[i]=max(pr[i-],query(s)); add(s);
}
cnt=; memset(c,,sizeof c); add();
for(int i=n,s=;i;i--)
{
s^=a[i];
sc[i]=max(sc[i+],query(s)); add(s);
}
int ans=;
for(int i=;i<n;i++)ans=max(ans,pr[i]+sc[i+]);
printf("%d\n",ans);
return ;
}

bzoj 4260 REBXOR —— Trie树的更多相关文章

  1. bzoj 4260: REBXOR Trie+乱搞

    题目大意: http://www.lydsy.com/JudgeOnline/problem.php?id=4260 题解: 啊啊啊. 被这种SB题坑了半天. 求出异或前缀和后 从n到1枚举\(r_1 ...

  2. bzoj 4260 Codechef REBXOR——trie树

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4260 一段的异或和就是两个前缀的异或和.正反扫两边,用trie树算每个位置为左/右端点时最大 ...

  3. BZOJ 4260: Codechef REBXOR (trie树维护异或最大值)

    题意 分析 将区间异或和转化为前缀异或和.那么[L,R][L,R][L,R]的异或和就等于presum[R] xor presum[L−1]presum[R]\ xor \ presum[L-1]pr ...

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

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

  5. bzoj4260 REBXOR——Trie树

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4260 对于每个位置,求一个前缀最大值和后缀最大值: 也就是从1到 i 的异或和要找前面某处的 ...

  6. 【bzoj4260】Codechef REBXOR Trie树

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

  7. 【bzoj4260】 Codechef REBXOR trie树

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

  8. BZOJ - 4260 01字典树+前后缀

    题意:给定\(a[1...n]\),求\((a_i⊕a_i+1⊕...⊕a_j)+(a_p⊕a_{p+1}⊕...⊕a_{q})\)的最大值,其中\(1≤i≤j<p≤q≤n\) 前后缀最优解预处 ...

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

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

随机推荐

  1. ExtNet配置webconfig

    <?xml version="1.0" encoding="utf-8"?> <!-- 有关如何配置 ASP.NET 应用程序的详细信息,请访 ...

  2. Maven使用site-deploy(site:deploy)部署通过site生成的文档(Tomcat-WebDAV)

    Maven可以通过site生成项目的帮助文档,并且格式为html,那么可以通过site-deploy把文档部署到远端,部署方式支持HTTP/FTP/SCM/WebDAV等. 更多部署方案,参考:htt ...

  3. 异常来自 HRESULT:0x800A01A8

    Windows 10 Enterprise Microsoft Office 2013 – Excel Oracle BI Publisher Desktop 11.1.1.7 异常来自 HRESUL ...

  4. Liunx常用命令(备用)

    常用指令 ls        显示文件或目录 -l           列出文件详细信息l(list) -a          列出当前目录下所有文件及目录,包括隐藏的a(all) mkdir     ...

  5. 转:linux下共享库的注意点之-fpic

    转: http://www.cnblogs.com/leo0000/p/5691483.html linux下共享库的注意点之-fpic 在编译共享库必须加上-fpic.这是为什么呢? 首先看一个简单 ...

  6. [WASM + Rust] Debug a WebAssembly Module Written in Rust using console.log

    Having some kind of debugging tool in our belt is extremely useful before writing a lot of code. In ...

  7. 王立平--GUI与GUILayout的差别

    GUI.Button (new Rect(0,0,5,5,"哈哈"); GUILayout.Button ("heheh"); 1.以上代码都是现实一个butt ...

  8. Golang之bytes.buffer

    bytes.buffer是一个缓冲byte类型的缓冲器存放着都是byte Buffer 是 bytes 包中的一个 type Buffer struct{-} A buffer is a variab ...

  9. HDU2489 Minimal Ratio Tree 【DFS】+【最小生成树Prim】

    Minimal Ratio Tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  10. angularjs中常见错误

    使用angularjs时间不是非常长,理解不够透彻.但为刚開始学习的人还是能够帮助点的. 1.回调函数. . ...-->切记它是异步的,出现莫名其妙的问题记得查看一下 2.内存泄露. .... ...