Dynamic Cactus
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 2 Accepted Submission(s): 1
Problem Description
Calcuate the longest simple path of a cactus which supports adding nodes and circles.
Input
Cases≤5 which denotes the number of test cases.
For each case , first line contains a single integer
T which denotes the number of operations.
Note nodes number with 1.Firstly,we only have one node numbered 1.
For each operation, there are two positive integer
x and
g,which denote the linked node and the number of adding nodes.
We let p donates the number of nodes before adding.
If g=1 , we add a node which links p+1 .
If g>1 , we add a circle p+1,p+2,...,p+g ,p+1 and p+g link with x ,p+i links with p+i+1
(1≤i<g).
The number of added nodes for each case not exceeding
105.
Output
For each case, output the answer after operating in a single line.
Sample Input
Sample Output
Hint
Source
Recommend
hujie | We have carefully selected several similar problems for you: 5352 5351 5350 5349 5348
解析:摘自:FancyCoder
/*
考虑离线,并对仙人掌进行分治。
类似于树的点分,每次的分治中心无非是两种情况:节点或者环。
这样每次新建节点时就去更新过分治中心的答案。
为了保证更新答案的两个点分属不同子树:
对于普通节点,只要维护最大和在另一子树的次大距离即可;对于环,由于环上的距离计算存在序的问题以及两种走法,我们可以在环上任选一个开始位置,需要分前后两部分更新和询问,可以用四个BIT维护前缀后缀和正负符号。
总时间复杂度为。
*/