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

于是选了个水题 然而写出了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. jpofiler监控JVM

    1.官方下载地址,选择自己想要的版本 https://www.ej-technologies.com/download/jprofiler/version_92 2.分为linux服务端.window ...

  2. I - Doing Homework again(贪心)

    I - Doing Homework again Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & ...

  3. jQuery实现鼠标放到图片上,放大图片

    <script src="../../Script/jquery-1.7.2.js" type="text/javascript"></scr ...

  4. Js计算时间差(天、小时、分钟、秒)

    <script type="text/javascript"> var date1= '2015/05/01 00:00:00'; //开始时间 var date2 = ...

  5. Java线程的5种状态及切换

    ava中的线程的生命周期大体可分为5种状态. 1. 新建(NEW):新创建了一个线程对象. 2. 可运行(RUNNABLE):线程对象创建后,其他线程(比如main线程)调用了该对象的start()方 ...

  6. java爬虫-简单爬取网页图片

    刚刚接触到“爬虫”这个词的时候是在大一,那时候什么都不明白,但知道了百度.谷歌他们的搜索引擎就是个爬虫. 现在大二.再次燃起对爬虫的热爱,查阅资料,知道常用java.python语言编程,这次我选择了 ...

  7. 提交cookie登录

    # coding:utf-8import requests # 先打开登录首页,获取部分cookieurl = "https://passport.cnblogs.com/user/sign ...

  8. 转载:Linux下查看/修改系统时区、时间

    一.查看和修改Linux的时区 1. 查看当前时区 命令 : "date -R" 2. 修改设置Linux服务器时区 方法 A 命令 : "tzselect" ...

  9. boost之内存池

    讲到内存池我们会想到对对象进行动态分配的过程new包含三个过程 1.使用operator new分配内存 2.使用placement new 初始化 3.返回内存地址. 分配内存可以分解成分配内存和获 ...

  10. Nginx和php-fpm部署到不同的服务器

    Nginx安装滤过,基本上nginx上的配置很少,只要添加个server就可以了,主要安装php-fpm服务 php7.1.3安装 1.安装依赖的软件包yum -y install gcc gcc-c ...