The xor-longest Path [Trie]】的更多相关文章

The xor-longest Path Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10038   Accepted: 2040 Description In an edge-weighted tree, the xor-length of a path p is defined as the xor sum of the weights of edges on p: ⊕ is the xor operator. W…
做该题之前,至少要先会做这道题. 记 \(d[u]\) 表示 \(1\) 到 \(u\) 简单路径的异或和,该数组可以通过一次遍历求得. \(~\) 考虑 \(u\) 到 \(v\) 简单路径的异或和该怎么求? 令 \(z=\operatorname{lca}(u,v)\) ,则 \(u\) 到 \(v\) 简单路径的异或和可以分成两段求解:一段是 \(z\) 到 \(u\) 简单路径的异或和,一段是 \(z\) 到 \(v\) 简单路径的异或和,二者异或一下即为 \(u\) 到 \(v\) 简…
We know that the longest path problem for general case belongs to the NP-hard category, so there is no known polynomial time solution for it. However, for a special case which is directed acyclic graph, we can solve this problem in linear time. First…
We all know that the shortest path problem has optimal substructure. The reasoning is like below: Supppose we have a path p from node u to v, another node t lies on path p: u->t->v ("->" means a path). We claim that u->t is also a sh…
The xor-longest Path Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6455 Accepted: 1392 Description In an edge-weighted tree, the xor-length of a path p is defined as the xor sum of the weights of edges on p: {xor}length(p)=\oplus{e \in p…
The xo-longest Path 题目描述 给定一棵\(n≤100 000\)个点的带权树,求树上最长的异或和路径. 输入 多组数据.每组数据第一行一个整数n(\(1≤n≤100 00\),接下去n-1行每行三个整数\(u(0≤u<n) ,v(0≤v<n) ,w(0≤w<2^{31})\),表示u和v之间的长度为w的边. 输出 对于每组数据输出结果. 样例输入 4 1 2 3 2 3 4 2 4 6 样例输出 7 题解 其实也是很简单的一道题,因为题目输入是一棵树,有边权,要我们求…
题目描述  给定一棵n个点的带权树,求树上最长的异或和路径 输入 The input contains several test cases. The first line of each test case contains an integer n(1<=n<=100000), The following n-1 lines each contains three integers u(0 <= u < n),v(0 <= v < n),w(0 <= w &l…
题意:给你一个序列(n<=100000),求出一个连续的子序列[i,j]使得ai xor ai+1 xor…… xor aj最大,求出这个最大值(其中每个数<=2^21) 分析:题目和求一段子序列的和或者积很像,只是运算法则改变,所以可以往求子段和.积的方法上面考虑 首先如果设sum[i]=a1 xor a2 xor a3……xor ai,则子序列[i,j]的xor值可以表达为sum[j] xor sum[i-1],这样是O(n^2)的是不行的 有以往的处理经验我们知道,后面那个j一定要枚举的…
代码写了不到30分钟,改它用了几个小时.先说题意,给你一颗树,边上有权,两点间的路径上的路径的边权抑或起来就是路径的xor值,要求的是最大的这样的路径是多少.讲到树上的两点的xor,一个常用的手段就是随便选一个根,然后深搜记下每个点v到根的xor路径 w[v],那么两点x,y路径的xor就是w[x]^w[y]. 深搜一发,问题转化为给你一个数组a,求a中哪两个数的抑或值最大.解决该问题的方法就是Trie树. 对每个权值由二进制高位到低位插到Trie树里,当要询问对于权值x最大的xor的时候,就需…
我的脑回路可能比较奇怪. 我们对这些询问离线,将所得序列${a}$的后缀和建$n$棵可持久化$trie$. 对于一组询问$(l,r,x)$,我们在主席树上询问第$l$棵树$-$第r$+1$棵树中与$suma[n']\ xor\ x$异或的最大值即可. 这个时间复杂度是$O(n\ log\ a)$的. #include<bits/stdc++.h> #define M 600005 using namespace std; ],sum=;}a[M*]; },use=; void updata(i…