Tree Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 102400/102400 K (Java/Others) Total Submission(s): 1643    Accepted Submission(s): 461 Problem Description   Zero and One are good friends who always have fun with each other. This time, t…
题目链接 \(Description\) 给定一棵树,点有点权.\(Q\)次询问\(x,y,z\),求\(x\)到\(y\)的简单路径中,与\(z\)异或能得到的最大的数是多少. \(Solution\) 对于给定数集的询问,我们可以建Trie树,从高位到低位贪心地走(能走优的就走). 同树上的主席树一样,利用父节点的根节点建树,就是可持久化Trie. 令\(w=LCA(u,v)\).因为只是xor一个数,所以用\(u,v,w\)三个点的根节点就可以了,最后再判断一下\(w\)是否可能更优(不需…
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…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4757 题意:给出一棵树,节点有权值.每次询问x到y的路径上与z抑或的最大值. 思路:可持久化trie. struct Node { int c[2],cnt; }; Node a[2000005]; int cnt; int newNode() { cnt++; a[cnt].c[0]=a[cnt].c[1]=a[cnt].cnt=0; return cnt; } struct node { int…
传送门 Tree Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 102400/102400 K (Java/Others) 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…
COT - Count on a tree #tree You are given a tree with N nodes.The tree nodes are numbered from 1 to N.Each node has an integer weight. We will ask you to perform the following operation: u v k : ask for the kth minimum weight on the path from node u …
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 will give One an tree and ev…
写过可持久化线段树,但是从来没写过可持久化的Trie,今天补一补. 题目就是典型的给你一个数x,和一个数集,问x和里面的某个数xor起来的最大值是多少. 最原始的是数集是固定的,只需要对数集按照高到低位去建Trie,然后贪心匹配就可以了. 这里则是对树上路径的操作,其实也是一样的,对每个节点x维护root到x的Trie,然后纪录下往左走往右走的叶子节点个数,设z=lca(x,y),那么到了个某个节点能否往某个儿子走的限制条件是 sz[ch[x][c]]+sz[ch[y][c]]-2*sz[ch[…
题意:询问树上结点x到结点y路上上的权值异或z的最大值. 任意结点权值 ≤ 2^16,可以想到用字典树. 但是因为是询问某条路径上的字典树,将字典树可持续化,字典树上的结点保存在这条路径上的二进制数. 按照dfs序建树,结点u的字典树表示u到根结点路径上的字典树. 如果两个结点u和v,在同一条通往根结点的路径上,将会满足可减性. 因此只需要知道u.v.lca和fa[lca]四个结点的字典树就可以回答了. /*********************************************…