解题思路:1.区间异或和可以搞前缀[or后缀]异或,xori=lra=pre[l]⊕pre[r]xor_{i=l}^{r}a=pre[l]\oplus pre[r]xori=lr​a=pre[l]⊕pre[r]
2.那么题目就变成了pre[l]⊕pre[r]+suf[l1]⊕suf[r1],pre是前缀异或和,suf是后缀异或和pre[l]\oplus pre[r] +suf[l_1]\oplus suf[r_1],pre是前缀异或和,suf是后缀异或和pre[l]⊕pre[r]+suf[l1​]⊕suf[r1​],pre是前缀异或和,suf是后缀异或和
3.对于一边相当于求任意两个pre[i]pre[i]pre[i]异或值最大,对于这种考虑两端的我们先预处理出一端再求另一个,我们就用一个dpdpdp数组存一下[1,i][1,i][1,i]每个位置选两个数的异或最大值然后再跑一遍逆序的相加就可以了


#include <iostream>
#include <cstdio>
#include <stack>
#include <sstream>
#include <limits.h>
#include <vector>
#include <map>
#include <cstring>
#include <deque>
#include <cmath>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <set>
#define mid ((l + r) >> 1)
#define Lson rt << 1, l , mid
#define Rson rt << 1|1, mid + 1, r
#define ms(a,al) memset(a,al,sizeof(a))
#define log2(a) log(a)/log(2)
#define _for(i,a,b) for( int i = (a); i < (b); ++i)
#define _rep(i,a,b) for( int i = (a); i <= (b); ++i)
#define for_(i,a,b) for( int i = (a); i >= (b); -- i)
#define rep_(i,a,b) for( int i = (a); i > (b); -- i)
#define lowbit(x) ((-x) & x)
#define IOS std::ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INF 0x3f3f3f3f
#define LLF 0x3f3f3f3f3f3f3f3f
#define hash Hash
#define next Next
#define pb push_back
#define f first
#define s second
using namespace std;
const int N = 4e5 + 10, mod = 1e9 + 9;
const long double eps = 1e-5;
const int EPS = 500 * 500;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef pair<double,double> PDD;
template<typename T> void read(T &x)
{x = 0;char ch = getchar();ll f = 1;while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
template<typename T, typename... Args> void read(T &first, Args& ... args)
{read(first);read(args...);
}
int n, idx;
int a[N];
int tr[31 * N][2];
int dp[N];
int pre[N], suf[N];
void insert(int x)
{int rt = 0;for(int i = 31; i >= 0; -- i){int ch = (x >> i) & 1;if(!tr[rt][ch]) {tr[rt][ch] = ++ idx;tr[idx][0] = tr[idx][1] = 0;}rt = tr[rt][ch];}
}int ask(int x)
{int rt = 0;int tmp = 0;for(int i = 31; i >= 0; -- i){int c = (x >> i) & 1;if(tr[rt][c ^ 1]) tmp += 1 << i, rt = tr[rt][c ^ 1];else rt = tr[rt][c];}return  tmp;
}int main()
{read(n);pre[0] = 0;for(int i = 1; i <= n; ++ i){read(a[i]);pre[i] = pre[i - 1] ^ a[i];}suf[n + 1] = 0;for(int i = n; i >= 1; -- i)suf[i] = suf[i + 1] ^ a[i];insert(0); for(int i = 1; i <= n; ++ i){dp[i] = max(dp[i - 1],ask(pre[i]));insert(pre[i]);}insert(0);tr[0][0] = tr[0][1] = idx = 0;int ans = 0;for(int i = n; i >= 2; i --){ans = max(ans,ask(suf[i]) + dp[i - 1]);insert(suf[i]);}cout << ans << endl;return 0;
}

Codechef REBXOR[dp+字典树]相关推荐

  1. [Bzoj4260]Codechef REBXOR(trie树)

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

  2. 【CODE】Unique Paths Word Search (DFS dp 字典树)

    目录 62. Unique Paths 63. Unique Paths II 980. Unique Paths III 79. Word Search 212. Word Search II 字典 ...

  3. bzoj 4260: Codechef REBXOR(01字典树)

    4260: Codechef REBXOR Time Limit: 10 Sec  Memory Limit: 256 MB Submit: 1281  Solved: 560 [Submit][St ...

  4. Codechef REBXOR HYSBZ - 4260(01字典树+区间异或最大)

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

  5. UVALive 3942 Remember the Word(字典树+DP)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  6. 经典算法题:字典树、并查集、单调栈、二分、带标记函数dp、树、全排列、字符串问题等常用算法

    0. Tips 1. 位运算 如何枚举一个二进制状态数字k的子集, 方法就是针对中的二进制为1的位开始进行减法,判断数字k的二进制子集, 像枚举(2^k-1) ~ 0一样枚举其子集: int sub ...

  7. CF633C Spy Syndrome 2(字典树+dp)

    CF633C Spy Syndrome 2 原题链接 说是 dpdpdp 但是感觉说是一个记忆化也可以.我们定义一个 dpdpdp 数组,其 dp[i]dp[i]dp[i] 含义为将加密串前 iii ...

  8. 词韵(字典树+DP)

    词韵 时间限制: 2 Sec  内存限制: 128 MB                                                                         ...

  9. 词韵 (字典树+树形DP)

    6360: 词韵 时间限制: 2 Sec  内存限制: 128 MB 提交: 136  解决: 19 [提交] [状态] [讨论版] [命题人:admin] 题目描述 Adrian 很喜欢诗歌中的韵. ...

最新文章

  1. sql 查询每月的销售金额
  2. Ocelot(三)- 服务发现
  3. java ee maven_针对新手的Java EE7和Maven项目–第7部分
  4. 牛客网-数据结构笔试题目(五)-动态规划问题求解
  5. SSAS的MDX的基础函数(二)
  6. mysql 动态插入日期_mysql 如何动态传入一个时间得到此时间的某个时间点
  7. [Web 前端] MobX
  8. 【DSP开发】DSP程序优化
  9. VS2013 Qt Unable to find a Qt Build 及 LINK1112错误
  10. oracle中on和where的区别,Oracle里面的外连中where和on之后and有啥区别
  11. linux怎么共享打印机驱动程序,Linux下使用局域网中windows 共享打印机
  12. 神经网络算法的关键参数,神经网络计算方法
  13. Android广告图片轮播,支持无限循环和设置轮播样式、切换时间等
  14. jquery图片放大镜插件—jqzoom
  15. numpy之生成随机数
  16. 【C# 教程系列第 29 篇】求1-100之内所有的质数(素数)
  17. 【机器学习】机器学习简介
  18. 融汇小学计算机课程,小学生电脑课上都学哪些知识和操作
  19. 常用CASE工具介绍及比较大全
  20. 「前端996」腾讯-QQ音乐-面试经历(整理)

热门文章

  1. RIP协议与OSPF协议与BGP协议
  2. MATLAB_8-边缘检测_黄晓明圈出人脸
  3. 基于OpenCV 的车牌识别
  4. 你可以恢复模糊的图像吗?
  5. 深度图像检测算法总结与对比
  6. 性能SOTA,国防科技大学单张RGB-D图像预测物体对称性
  7. Installing Oracle Database 18c Using RPM Packages
  8. Linux之网络管理(2)虚拟网卡
  9. Git入门教程(上)
  10. wordpress关闭博客评论的两种方法