cdqz2017-test8-Tree(点分树)】的更多相关文章

A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties: The left subtree of a node contains only nodes with keys less than the node's key. The right subtree of a node contains only nodes with keys greate…
已经连咕了好几天博客了:比较经典的题目 题目大意 给出一个 N 个点的树和$K_i$, 求每个点到其他所有点距离中第 $K_i$ 小的数值. 题目分析 做法一:点分树上$\log^3$ 首先暴力做法:对于每个节点维护其他点距离的值域线段树.这个做法的瓶颈在于关于边$(u,v)$线段树的转移.那么可以利用点分树(为了保证复杂度)换一种容斥的思路利用重复的信息:记$f_i$为以$i$为根的点分树内所有其他点到点$i$的距离的值域线段树:$g_i$为以$i$为根的点分树内,所有点到$i$的点分树父亲的…
淀粉质点分治可真是个好东西 Part A.点分治 众所周知,树上分治算法有$3$种:点分治.边分治.链分治(最后一个似乎就是树链剖分),它们名字的不同是由于分治方式的不同的.点分治,顾名思义,每一次选择一个点进行分治,对于树上路径统计类型的问题有奇效,思路很好理解,只是码量有些烦人 先来看一道模板题:CF161D 至于为什么我没有放Luogu模板题是因为那道题只会写$O(n^2logn)$的算法(然而跑得过是因为跑不满) 这道题要求在$N$个点的树上找距离为$K$的点对的数量. 因为我们是来学点…
题目描述 Atm有一段时间在虐qtree的题目,于是,他满脑子都是tree,tree,tree…… 于是,一天晚上他梦到自己被关在了一个有根树中,每条路径都有边权,一个神秘的声音告诉他,每个点到其他的点有一个距离(什么是距离不用说吧),他需要对于每个点回答:从这个点出发的第k小距离是多少: 如果atm不能回答出来,那么明天4019的闹钟将不会响,4019全寝可能就迟到了,所以atm希望你帮帮他. 输入 第一行,两个正整数n,k,表示树的点数,询问的是第几小距离: 第二~n行,每行三个正整数x,y…
题目 描述 ​ 有两棵树\(T\)和\(T'\),节点个数都为\(n\),根节点都为\(1\)号节点; ​ 求两两点之间 $$ \begin{align} depth(x) + depth(y) - depth(LCA(x,y)) - depth'(LCA'(x,y)) \end{align} \ 其中depth(x)为x和1号节点的树上距离 \ $$ ​ 的最大值: 范围 ​ $1 \le n \le 366666 $ : 题解 原式 = \(\frac{(dep(x) + dep(y) +…
n个点的带点权带边权的树,设点权为a[i],边权为b[i] 一棵树有n*(n-1)/2个点对, 定义这棵树的价值为任意两点对的(a[x]^a[y])*dis(x,y) 有m次修改一个点的点权的操作 输出每次修改完点权后这颗树的价值 第i次的修改会影响到第i次之后的修改 第一眼:我靠怎么又是点分树 然后因为没有处理好选的点对和自己处于根的同一子树,一下午过去了,一晚上过去了,又一个晚上过去了...... 吐槽结束,下面是题解 异或-->按位操作,点权变为1或者0,第i位的答案乘上2^i即可 点分治…
传送门 题目就是要求维护带权重心. 因此破题的关键点自然就是带权重心的性质. 这时发现直接找带权重心是O(n)的,考虑优化方案. 发现点分树的树高是logn级别的,并且对于以u为根的树,带权重心要么就是u,要么存在于u的某一个儿子为根的子树中. 由于带权重心只有一个,因此只需要从根节点开始向下跳,跳不动了就是答案. 代码: #include<bits/stdc++.h> #define N 100005 #define ll long long using namespace std; inl…
题目地址 https://pta.patest.cn/pta/test/16/exam/4/question/668 5-6 Root of AVL Tree   (25分) An AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two child subtrees of any node differ by at most one; if at any time they d…
1064 Complete Binary Search Tree (30 分)   A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties: The left subtree of a node contains only nodes with keys less than the node's key. The right subtree of a…
1043 Is It a Binary Search Tree (25 分)   A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties: The left subtree of a node contains only nodes with keys less than the node's key. The right subtree of a…