之前写字典树虽然很熟也能变化 但是一直是到了场上再乱写 写的很长 于是准备写个短点的板子

于是选了个水题 然而写出了1W个bug

insert和query反而写的没什么问题..

L c[100050] ;

struct node {
L v[2] ;
L num[2] ;
}a[100000 * 64];
L tot ;
L b[100] ;
L f[100] ;
node newnode() {
node cc ;
cc.v[0] = cc.v[1] = -1 ;
cc.num[0] = cc.num[1] = 0 ;
return cc ;
}
void init() {
tot = 0 ;
f[60] = 1 ;
dow(i,59,1) {
f[i] = f[i+1] * 2 ;
}
a[0] = newnode() ;
}
void fj(L x) {
dow(i,60,1) {
b[i] = x%2 ;
x/=2 ;
}
}
void inse(L z,L val) {
fj(z) ;
L rt = 0 ;
rep(i,1,60) {
L x = b[i] ;
if(a[rt].v[x] == -1) {
tot ++ ;
a[rt].v[x] = tot ;
a[tot] = newnode() ;
}
a[rt].num[x] += val ;
rt = a[rt].v[x] ;
}
}
L query(L z) {
fj(z) ;
L rt = 0 ;
L ans = 0 ;
rep(i,1,60) {
L x = b[i] ;
if(a[rt].num[x^1] > 0 && a[rt].v[x^1] != -1) {
ans += f[i] ;
rt = a[rt].v[x^1] ;
}
else {
rt = a[rt].v[x] ;
}
}
return ans ;
} L sum[100050] ; int main () {
L n ;
while(scanf("%lld" , &n) != EOF) {
init() ;
rep(i,1,n) c[i] = read() ;
sum[0] = 0 ;
rep(i,1,n) {
sum[i] = c[i] ^ sum[i-1] ;
}
rep(i,0,n)
inse(sum[i],1) ;
L res = 0 ;
L ans = query(0) ;
dow(i,n,1) {
inse(sum[i],-1) ;
res ^= c[i] ;
ans = max(ans , query(res)) ;
}
printf("%lld\n" , ans) ;
}
}

HRBUST 1717 字典树模板的更多相关文章

  1. 字典树模板题(统计难题 HDU - 1251)

    https://vjudge.net/problem/HDU-1251 标准的字典树模板题: 也注意一下输入方法: #include<iostream> #include<cstdi ...

  2. CH 1601 - 前缀统计 - [字典树模板题]

    题目链接:传送门 描述给定 $N$ 个字符串 $S_1,S_2,\cdots,S_N$,接下来进行 $M$ 次询问,每次询问给定一个字符串 $T$,求 $S_1 \sim S_N$ 中有多少个字符串是 ...

  3. hdu1521(字典树模板)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1251 题意: 中文题诶~ 思路: 字典树模板 代码1: 动态内存, 比较好理解一点, 不过速度略慢, ...

  4. HDU - 1251 字典树模板题

    Ignatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单词数量(单词本身也是自己的前缀).  Input输入数据的第一部 ...

  5. 字典树模板 HDU - 1251

    题意: 给一些单词,换行键后,查找以后输入的单词作为前缀的话们在之前出现过几次. 思路: 字典树模板----像查字典的顺序一样 #include<string> #include<s ...

  6. P1184 高手之在一起(字典树模板题,hash算法, map)

    哎,唯一值得说明的是,这道题的输入有bug 先把字典树的算法模板放一下 #include<iostream> #include<cstring> using namespace ...

  7. hdu 1671 Phone List 字典树模板

    Given a list of phone numbers, determine if it is consistent in the sense that no number is the pref ...

  8. 字典树模板( 指针版 && 数组版 )

    模板 :  #include<string.h> #include<stdio.h> #include<malloc.h> #include<iostream ...

  9. Xor Sum---hdu4825(01字典树模板)

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=4825 题意:有n个数m个查找,每个查找有一个数x, 从序列中找到一个数y,使得x异或y最大 ...

随机推荐

  1. 47、ListView setSelection() 和 setSelectionFromTop()

    http://blog.csdn.net/manoel/article/details/39183025 http://blog.csdn.net/a859522265/article/details ...

  2. ofstream和ifstream详细用法

    ASCII和二进制文件的输入输出 First:包含头文件#include <fstream> ASCII输入: 首先要创建一个in-stream对象:ifstream fin(" ...

  3. Palindrome Function

    Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 256000/256000 K (Java/Others)Total Submissio ...

  4. maven实现项目热部署

    1.Tomcat的配置 我们需要实现热部署,自然就需要通过maven操作tomcat,所以就需要maven取得操作tomcat的权限,现在这一步就是配置tomcat的可操作权限. 在tomcat的安装 ...

  5. Martin Fowler’s Active Record design pattern.

    P of EAA: Active Record https://www.martinfowler.com/eaaCatalog/activeRecord.html Active Record An o ...

  6. 【转】图解MySql命令行创建存储过程

    一 操作实例 首先登录mysql: 使用source命令,从命令行执行sql脚本,创建表: 创建第一个存储过程: 事先用DELIMITER关键字申明当前段分隔符,这样MySQL才会将";&q ...

  7. Testlink安装:Notice:Undefined index: type in C:\inetpub\wwwroot\testlink-1.9.3\install\installCheck.php on line 41

    问题现象:

  8. 如何在Pycharm设置ES6语法环境

    首先 如果不进行相关设置就刚ES6 语法的话,会出现下面提示性错误(运行还是能正常出效果的): (let 飘红, 这只是其中之一, 其他语法也会飘红) 接着,就是解决问题: 首先打开设置: 接着找到下 ...

  9. Andrew Ng机器学习编程作业: Linear Regression

    编程作业有两个文件 1.machine-learning-live-scripts(此为脚本文件方便作业) 2.machine-learning-ex1(此为作业文件) 将这两个文件解压拖入matla ...

  10. 详解mysql数据库的左连接、右连接、内连接的区别

    一般所说的左连接,外连接是指左外连接,右外连接.做个简单的测试你看吧. 先说左外连接和右外连接: SQL>select * from t1; ID NAME ---------- ------- ...