HDU 4757 Tree 可持久化字典树 trie】的更多相关文章

http://acm.hdu.edu.cn/showproblem.php?pid=4757 给出一棵树,每个节点有权值,每次查询节点 (u,v) 以及 val,问 u 到 v 路径上的某个节点与 val 异或最大的值是多少. 和可持久化线段树差不多,看代码吧. #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<iostream> #in…
Tree Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4757 Description Zero and One are good friends who always have fun with each other. This time, they decide to do something on a tree which is a kind of graph…
题目链接 题意:有一棵树,树根为1,树上的每个结点都有一个数字x.给出Q组询问,每组询问有两个值u,x,代表询问以结点u为根的子树中的某一个数与x的最大异或值. 解法一:dfs序+可持久化字典树.看到子树询问,首先要想到dfs序啦.可以对所有结点按dfs序依次建立可持久化的字典树,字典树上的每个结点除了要保存它的后继结点以外,还要保存这个结点出现的次数num.询问结点u时,对[bg[u],ed[u]]上的字典树的num做差,字典树上剩下的num>0的结点即为可行状态,然后按普通的字典树的查询方法…
题目链接:点这 我的github地址:点这     Problem Description   Zero and One are good friends who always have fun with each other. This time, they decide to do something on a tree which is a kind of graph that there is only one path from node to node. First, Zero wi…
题目链接 Problem Description Monkey A lives on a tree, he always plays on this tree. One day, monkey A learned about one of the bit-operations, xor. He was keen of this interesting operation and wanted to practise it at once. Monkey A gave a value to eac…
题目链接 \(Description\) 给定一棵树,点有点权.\(Q\)次询问\(x,y,z\),求\(x\)到\(y\)的简单路径中,与\(z\)异或能得到的最大的数是多少. \(Solution\) 对于给定数集的询问,我们可以建Trie树,从高位到低位贪心地走(能走优的就走). 同树上的主席树一样,利用父节点的根节点建树,就是可持久化Trie. 令\(w=LCA(u,v)\).因为只是xor一个数,所以用\(u,v,w\)三个点的根节点就可以了,最后再判断一下\(w\)是否可能更优(不需…
题目 给出一棵有n个结点的树,树根是1,每个结点给出一个value.然后给出q个询问,每个询问给出两个整数u和x,你要在以u结点为根的子树中找出一个结点v,使得val[v] xor x最大, 并输出这个最大值 分析 显而易见的可持久化字典树,只不过这次每次查询不是查询一个区间,而是查询一棵子树.那么也很简单,我们只要预处理出dfs序然后找出每个结点以它为根的子树在dfs序中的区间.然后以这个区间建可持久化字典树就可以了. #include <cstdio> #include <cstri…
You are given a sequence A[1], A[2], ..., A[N]. (0 ≤ A[i] < 231, 1 ≤ N ≤ 12000). A query is defined as follows: Query(x,y) = Max { a[i] xor a[i+1] xor ... xor a[j] ; l ≤ i ≤ j ≤ r }. l = min ( ((x+lastans) mod N)+1 , ((y+lastans) mod N)+1 ). r = max…
一. 题目 487-3279 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 274040   Accepted: 48891 Description Businesses like to have memorable telephone numbers. One way to make a telephone number memorable is to have it spell a memorable word or…
字典树trie的思想就是利用节点来记录单词,这样重复的单词可以很快速统计,单词也可以快速的索引.缺点是内存消耗大 http://blog.csdn.net/chenleixing/article/details/44708533  这个是学习资料来源. 附上个人代码实践操作 package ShuJujieGou; import javax.swing.tree.TreeNode; public class Tries { private int deepLength; private int…