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

于是选了个水题 然而写出了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. FileToolkit 文件工具箱

    import org.apache.commons.io.FileUtils; import org.apache.commons.io.filefilter.*; import org.apache ...

  2. codeblocks在进行多线程出现phread问题

    undefined reference to 'pthread_create' 出现这个错误是因为编译默认不会链接进程库. 可以选择用gcc进行编译 加上-lpthread 比如:gcc exampl ...

  3. android菜鸟学习笔记27----Fragment的简单使用

    1.Fragment的生命周期: 简单在新建一个MyFragment继承自Fragment,重写各个生命周期回调方法,各个方法中直接输出标识相关函数被调用的信息. 重写MainActivity的各个生 ...

  4. es 中 for in for of

    arr=[11,22,33,44,55,66,77,88]for (const i in arr){ console.log(i) if (i===4){ console.log(arr[i]) }} ...

  5. Java 注解入门

    1.什么是注解 注解的语法: @注解名称; 注解的作用: 用来替代 xml 配置文件; 在 Servlet 3.0 中就可以使用注解来代替配置文件; 注解是由框架来读取使用的; 所有的注解都是 Ann ...

  6. make menuconfig 时出现 mixed implicit and normal rules: deprecated syntax

    這是 make 的版本問題!不清楚為何要這樣限制? 將此行          config %config: scripts_basic outputmakefile FORCE改成          ...

  7. djange数据库优化操作

    一.all()命令分析 1.user_list = models.UserInfo.objects.all()    #查询表一次可以得到该表的所有信息 注释:user_list.query可以查询到 ...

  8. linux环境变量 【转】

    Linux 的变量可分为两类:环境变量和本地变量 环境变量,或者称为全局变量,存在与所有的shell 中,在你登陆系统的时候就已经有了相应的系统定义的环境变量了.Linux 的环境变量具有继承性,即子 ...

  9. Nginx负载均衡案例

    nginx负载均衡配置,windows版本和linux版本的nginx除了启动方式其他基本无差异. 1.Niginx安装 参考:https://www.cnblogs.com/zwcry/p/9454 ...

  10. 开发自己的composer package

    参考:https://laravel-china.org/articles/6652/learn-to-develop-their-own-composer-package-and-to-use-pa ...