Hi. I am reading Efficient and easy segment trees(bottom-up approach) and I solved a problem "Assignment to Segment" from edu(the problem is about interval assign). But I can't prove why it's sufficient to propagate only parents of l
and r - 1
. Can anybody help me to prove it? Problem link
My code
Your question was really helpful for me. I will try to give you a direction to think.
Firstly I understand your question this way — when asked to assign v from l to r, why is it sufficient to lazily push values for ancestors of l and r only and then perform our operation?
So I drew out a 8 sized segment tree(you try too) and saw for different queries how your algorithm works. Specifically for the push function. You will see that the pushed values for l if go to the left, are not changed and the right ones get updated while doing our update operation. Similar thing happens with r also.
hope it helps clarify things.
As you can see assignment operation is not just non-commutative but also that only the latest assignment matters. So you can just store time of some operation and make a normal commutative type segtree. Just for the point query you take latest assignments from all the parents and the 'combine' operation combines two elements and gives out the more recent element.
Let
S
be the set of nodes "making up" the interval[L, R)
. Notice for all nodesk
∈S
:k
's parent's interval ⊈[L, R)
(otherwise it's better to takek
's parent).Now consider if
l&1
is true at some depth (sol
∈S
). It's enough to show thatl
's parent is an ancestor of leafL
(since then, every ancestor ofl
is an ancestor of leafL
, so propagating all ancestors of leavesL
,R-1
is the same as propagating all ancestors of all nodes ∈S
).Let
l
's parent's interval be[par_l, par_r)
. We know[par_l, par_r)
⊈[L, R)
(so eitherpar_l < L
orR < par_r
).But since
l
is odd, it is the right child ofl
's parent (so their intervals share a right-endpoint). Sincel
's interval ⊆[L, R)
:par_r <= R
. Sopar_l < L
. SoL
∈l
's parent's interval. Sol
's parent is an ancestor of leafL
.