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

于是选了个水题 然而写出了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. Javascript中的函数中的this值

    看下面这段代码会在控制台上输出什么内容? <script> var url="fang.com"; var obj={ url:"soufun.com&quo ...

  2. Parenthesis(前缀和+线段树)

    1809: Parenthesis Time Limit: 5 Sec     Memory Limit: 128 Mb     Submitted: 2291     Solved: 622 Des ...

  3. 【转】.Net 程序集 签名工具sn.exe 密钥对SNK文件 最基本的用法

    阐述签名工具这个概念之前,我先说说它不是什么: 1.它不是用于给程序集加密的工具,它与阻止Reflector或ILSpy对程序集进行反编译一毛钱关系都没有. 2.它很讨厌人们把它和加密联系在一起. 我 ...

  4. RedHat6/Centos6.5安装mongodb php driver

    条件: 安装apache 安装php 1.下载mongodb phh driver 下载地址:pecl wget http://pecl.php.net/get/mongo-1.5.8.tgz 2.解 ...

  5. margin 依附与可见的内容,不能为margin而写margin

    margin  依附于可见的内容,不能为margin而写margin <!DOCTYPE html><html><head><style> p{marg ...

  6. php自定义函数: 时间转换成智能形式

    function time_trans($paratime,$suffix=false){ $now_time = time(); $dur = $now_time - $paratime; $suf ...

  7. 【转】虚拟 IO 服务器(VIOS)和 IBM i

    Power 主机上的虚拟化应用,简单阐述虚拟 IO 服务器的功能,用途,优点,以及虚拟 IO 服务器在高级虚拟化技术的作用.举例说明虚拟 IO 服务器与 IBM i 分区直接互联特性. 引言 随着信息 ...

  8. es6数组的一些函数方法使用

    数组函数forEach().map().filter().find().every().some().reduce()等 数组函数(这里的回调函数中的index和arr都可以省略,回调函数后有参数是设 ...

  9. python函数回顾:all()

    描述 all() 函数用于判断给定的可迭代参数 iterable 中的所有元素,是否不为 0.''.False 或者 iterable 为空,如果是返回 True,否则返回 False. 如果是空元组 ...

  10. document write & close

    在载入页面后,浏览器输出流自动关闭.在此之后,任何一个对当前页面进行操作的document.write()方法将打开—个新的输出流,它将清除当前页面内容. 必须确保调用document.close() ...