1. tree cover tree
(1) Fenwick tree cover Fenwick tree
Front:
How Fenwick tree support plus range and range queries
Maintain a differential array to find a position of value, we just need to prefix and seen as a rectangle,
Minus the contribution of two numbers can be generated by interpolating
1.P4514 God made the title of seven minutes
Meaning of the questions: support plus a number of rectangular and rectangular query values.
Consider each point differential, when we want to \ ((a, b), (x, y) \) matrix plus 1:00 range, in fact:
\(A(a,b)+1\)
\(A(x,b+1)-1\)
\ (A (a, y + 1) -1 \)
\ (A (x + 1, y + 1) +1 \)
Ever since, the prefix and:
\[\sum_{i=a}^x\sum_{j=b}^yA(i,j)*(x-i+1)*(y-j+1)\]
\[\sum_{i=a}^x\sum_{j=b}^yA(i,j)*(x*y+1)+A(i,j)*i*j-A(i,j)*i*(y+1)-A(i,j)*j*(x+1)\]
维护\(A(i,j)*i*j,A(i,j)*i,A(i,j)*j,A(i,j)\)即可
(2) the weight section sleeve segment tree segment tree
1.P3332 [ZJOI2013] K Tarsus inquiry
Meaning of the questions:
1 abc: b represents the first position in a first position, each position plus a number c
2 abc: represents a query from the first position to the second position b, the large number is the number of C
Directly on. . .
(3). Fenwick tree sets Chairman tree
We found that a single tree is similar to our chairman of a prefix and a single. When we need a point to be repaired
Change, and evaluation, we consider the relationship with Fenwick tree maintenance intervals, the changes to the number of times every fall to
\ (O (log ^ 2n) \) , but each time the query has become such complexity.
1.P2617 Dynamic Rankings 裸题
2. Dynamic reverse order
3.P4175 [CTSC2008] Network Management
Meaning of the questions: Maintenance k-th largest value on a chain in a tree, and supports the changes.
Solution: Direct tree cover tree and then set a tree section, excellent \ (O (nlog ^ 3n) \)
(4) sets of balanced tree segment tree
1.P3380 [template] two forced balanced tree (tree cover tree)
A giant giant did not say what, in fact, that if I make myself \ (yy \) out of the \ (O (log ^ 3n) \) approach,
But konjac comes with a large constant, that is, not before.
2. Point Divide and Conquer
Dotted rule complexity that each time seeking the right side of the center of gravity, maintaining the height of the tree, the total complexity is
\ (O (nlog n) \ ) of
1.P3806 [template] partition 1 point
Solution: roll rough board
2.P4149 [IOI2011]Race
Solution: Multi maintain a number of side
3.P2634 [National Team] Cong Cong cocoa
Solution: roll rough board
3. Dynamic dotted rule
Dynamic point of divide and conquer is to support changes to it. . . . . .
Then we know would have dotted rule is to constantly find the center of gravity, so based on this we can build out a dotted
Tree, very good. And we know that in fact every point of divide and conquer is nothing more than the sum of the center of gravity of each answer. I
The answer to each of the center of gravity are recorded directly. Built out of sub-tree complexity point is still very secure.
Divide and Conquer is still very dynamic point gives revelation.
1.P3345 [ZJOI2015] township fantasy strategy game
Meaning of the questions: a tree, there is the right side, right to the point. Support the right to modify the point, asked to identify a point, all points
* Weights and the minimum distance to this point.
answer:
1. The beautiful nature of this question is to find the tree's center of gravity.
2. If this question directly to the center of gravity to meet the $ 2 \ times sumd_v> sumd_u $ then go to v.
3. We want to focus all statistics are from this point * weights. Dotted tree can be done. It looks like this:
ll count(int x){
ll res = 0 ;
res += sumval[x] ;
for(int i = x ; Hfa[i] ; i = Hfa[i] ){
ll fr = Distance( x , Hfa[i] ) ;
res += ( sumval[Hfa[i]] - sumf[i] ) ;
res += 1ll * ( sumg[Hfa[i]] - sumg[i] ) * fr ;
}
return res ;
}
ll query(int x){
ll tmp = count( x ) ;
for(int i = Fire[x] ; i ; i = Nex[i] ){
int v = To[i] ;
if( count( v ) < tmp ) return query( near[i] ) ;
}
return tmp ;
}
2.P3241 [HNOI2015] shop
This question is in fact the same as the above routine, dotted tree to build a wave, vector record wave.
3.P3676 small fresh data structure that
God is a problem.
We \ (S_i \) represents \ (i \) of the sub-tree
Here you will find \ (\ sum_ {i = 1 } ^ nS_i ^ 2 \) is a very good deal and what is not very beautiful nature
We do not consider amending the first, let's look at the root change back to produce what kind of impact:
If the tree is this. Now with (5 \) \ dot is the root, and now intend to \ (1 \) dot the root
It found that only the path \ (1-5 \) subtree size becomes the point. So you'll find a beautiful and terrible knot
s:
\[\sum_{i=1}^nS_i(Sum-S_i)\]
It is a constant. This setting is set \ (W is \)
The answer is
\[ans=Sum\sum_{i=1}^nS_i-W\]
however
\[\sum_{i=1}^nS_i=\sum_{i=1}dep_ivali\]
The dotted tree can be directly qualified
We began to consider modifying a single point.
For any two points, the contribution of their product produced both for them just have not been classified in the same sub-tree.
Such a situation there \ (dis (i, j) \) times
and so
\[\sum_{i=1}^nS_i(Sum-Si)=\sum_{i=1}^n\sum_{j=1}^ndis(i,j)val_ival_j\]
For single-point modification:
\ [W_ {new} = add * \ sum_ {j = 1} ^ ndis (i, j) * val_j \]
This, then, is capable dotted tree
And similar wording above
4. hide and seek P2056 [ZJOI2007] hide and seek
I did not say hard code, you can learn is to use the heap
struct node{
priority_queue<int> A , B ;
void insert(int x){
A.push(x) ;
}
void dele(int x){
if( A.top() == x ) A.pop() ;
else B.push(x) ;
}
int Top(){
while( !A.empty() && !B.empty() && A.top() == B.top() ) A.pop() , B.pop() ;
if( A.empty() ) return -inf ;
else return A.top() ;
}
int nex_top(){
int rt = Top() ;
if( rt == -inf ) return -inf ;
A.pop() ; int nexrt = Top() ;
A.push( rt ) ;
return nexrt ;
}
}ans , tofa[N] , stree[N] ;
4.LCT
(1) Chain Information:
1.P1501 [National Team] Tree II
2.P2147 [SDOI2008] cave survey
3.P3690 [template] Link Cut Tree (dynamic tree)
4.P4332 [SHOI2014] trigeminal nerve tree
被神仙叫做模板题。每棵平衡树在其中维护最深不是2的以及最深不是1的点。然
后乱搞就行。
(2)维护图连通性:
1.P2387 [NOI2014]魔法森林
排个序,维护一波。
2.P2542 [AHOI2005]航线规划
维护双连通,倒叙做
3.P4234 最小差值生成树
这里的话需要先新建节点,表示两点之间的边权。维护链的最小值,删掉就行。
4.P4172 [WC2006]水管局长
不知道为什么别人一个个跑得飞快。这道题,也就是维护一个最大边,形成一个
圈就删去即可。
(3)维护子树信息:
1.P4219 [BJOI2014]大融合
注意虚子树修改在\(link\)和\(access\)中要进行。
2.P3703 [SDOI2017]树点涂色
在浑浊的\(LCT\)中,这简直就是一股清流。
线段树\(dfs\)序来维护一棵子树的颜色总和。
每次将根到某个点的链全部染成同一种颜色就是一次\(access\)操作。于是乎
\(access\)每断一次边下面的原来链的子树答案加1,新加入的链的子树答案全部减
1
5.树链剖分
这是一个收集篇,收集树剖好题。
1.P4211 [LNOI2014]LCA
建个下标为标号的主席树的dfs序(维护区间差分个数)
6.扫描线
1.P1972 [SDOI2009]HH的项链
感受一下
2.P4113 [HEOI2012]采花
感受一下
3.P1856 [USACO5.5]矩形周长Picture
luogu无矩形面积并,不过这个也差不多。
跑两边扫描线,每次加差值就行。