我们给出一棵树 T
,和一组初始为空的节点 P={}
。
我们有 3 种操作:
1.add a node to `P`
2.delete a node from `P`
3.Query for maximum distance in set `P`
我们总共有 q
次操作,时间限制说我们应该在 O(q* log(n)) 中完成整个操作。
所以我们需要在O(log(n))
到目前为止,我是这样做的:
keep track of max distance in each insert/delete operation.
for insert it's just to check the distance of added node from two previous max nodes
for the query it's just return max_distance
但是对于 delete
操作,我不能做得比 O(n)
更好(在没有任何进一步信息的情况下找到树上节点集之间的最大距离)
对此有任何O(log(n))
解决方案吗?