题目链接 题意:有一棵树,树根为1,树上的每个结点都有一个数字x.给出Q组询问,每组询问有两个值u,x,代表询问以结点u为根的子树中的某一个数与x的最大异或值. 解法一:dfs序+可持久化字典树.看到子树询问,首先要想到dfs序啦.可以对所有结点按dfs序依次建立可持久化的字典树,字典树上的每个结点除了要保存它的后继结点以外,还要保存这个结点出现的次数num.询问结点u时,对[bg[u],ed[u]]上的字典树的num做差,字典树上剩下的num>0的结点即为可行状态,然后按普通的字典树的查询方法…
Query on A Tree Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others) Total Submission(s): 712    Accepted Submission(s): 266 Problem Description Monkey A lives on a tree, he always plays on this tree. One day, monke…
题意 \(n\) 个点的有根树,根为 \(1\) .每个点有点权,有 \(q\) 个询问,每次询问以 \(u\) 为根的子树的点的点权中异或 \(x\) 所得的最大值是多少. 思路 求出整棵树的 \(\text{dfs}\) 序,问题就转化成了序列上,求一个区间中的数字异或 \(x\) 可得的最大值.同样的方法,只需在原序列上建立可持久化的 \(\text{Trie}\) 树即可,和区间第 \(K\) 值类似的方法,在 "主席\(\text{Trie}\) "上找最大解. 代码 #in…
题目链接 题意 : 给你一棵树.树上的每个点都有点权.之后有若干次问询.每次问询给出一个节点编号以及一个整数 X .问你以给出节点为根的子树中哪个节点和 X 异或最大.输出这个值 分析 : 看到这种树上异或最值的问题 可以考虑使用 Trie 来解决 首先涉及到子树 我们可以利用 DFS 序来构造出每个根的子树 DFS 序有很好的性质.其子树的所有节点必定是序列中连续的一段 那么我们就可以对这个 DFS 序列建立可持久化 Trie 然后通过类似前缀和减法的方式得到问询节点子树表示的区间中 所有数组…
Query on A Tree Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others)Total Submission(s): 733    Accepted Submission(s): 275 Problem Description Monkey A lives on a tree, he always plays on this tree. One day, monkey…
Query on A Tree Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others)Total Submission(s): 1238    Accepted Submission(s): 444 Problem Description Monkey A lives on a tree, he always plays on this tree.One day, monkey…
BZOJ_1803_Spoj1487 Query on a tree III_主席树 Description You are given a node-labeled rooted tree with n nodes. Define the query (x, k): Find the node whose label is k-th largest in the subtree of the node x. Assume no two nodes have the same labels. I…
[BZOJ1803]Spoj1487 Query on a tree III Description You are given a node-labeled rooted tree with n nodes. Define the query (x, k): Find the node whose label is k-th largest in the subtree of the node x. Assume no two nodes have the same labels. Input…
You are given a node-labeled rooted tree with n nodes. Define the query (x, k): Find the node whose label is k-th largest in the subtree of the node x. Assume no two nodes have the same labels. Input The first line contains one integer n (1 <= n <=…
Code: #include<iostream> #include<cstdio> #include<algorithm> #include<string> #include<cstring> #define REP(i,a,n)for(int i=a;i<=n;++i) #define CLR(d,a)memset(d,a,sizeof(d)); using namespace std; void SetIO(string a){ str…