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

于是选了个水题 然而写出了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. 内核源码阅读vim+cscope+ctags+taglist

    杜斌博客:http://blog.db89.org/kernel-source-read-vim-cscope-ctags-taglist/ 武特博客:http://edsionte.com/tech ...

  2. 巨蟒python全栈开发linux之centos4

    1.linux虚拟环境1-4 2.linux运行crm代码

  3. Xcode生成ipa文件

    想到蒲公英应用做分发测试的同学们可以用的到哈 在测试的Device中切换为IOS Device,选择当前项目修改BuildSeting 在code signing Identity中选择证书,没有测试 ...

  4. iOS反射:把对象直接转化成NSDictionary

    在IOS的网络编程中,通常我们需要将一些实体数据保存到NSDictionary,在获得NSDictionary后即可直接使用iOS 5后的NSJSONSerialization类型的dataWithJ ...

  5. C# 自定义控件摘记

    C# 自定义控件属性 现有自定义控件,内有一textbox控件 TextBox1.控件有一属性 Value 定义为 [BrowsableAttribute(true)] [BindableAttrib ...

  6. 我的Android进阶之旅------>Android中查看应用签名信息

    一.查看自己的证书签名信息 如上一篇文章<我的Android进阶之旅------>Android中制作和查看自定义的Debug版本Android签名证书>地址:http://blog ...

  7. python基础:while循环,for循环

    ---恢复内容开始--- 1.使用while循环输出1 2 3 4 5 6     8 9 10 2.求1-100的所有数的和 3.输出 1-100 内的所有奇数 4.输出 1-100 内的所有偶数 ...

  8. c语言复制文件程序

    #include <stdio.h> #include <stdlib.h> #include <string.h> #define SIZE 1024*1024* ...

  9. 找出n的阶乘末尾有几个零

    原理:因为10由2*5组成,而构成2的因数比5多 所以最终转换成求5的个数 int getNumber(int n) { int count = 0; while(n) { n = n/5; coun ...

  10. cut命令学习

    cut最基本的用法: -f 列号:提取第几列 -d 分隔符:按照指定分隔符分割列(默认是制表符tab) 测试用例:(制表符)