FluffyPotato's blog

By FluffyPotato, history, 5 years ago, In English

Hello all

Typically lazy propagation and segment tree updates come in the form "increase range l-r by diff". What if you want to update a segment tree like "update range l-r to val". So instead of a difference, you tell it precisely what number to update to.

How would you do this? Is there an article somewhere about this?

  • Vote: I like it
  • 0
  • Vote: I do not like it

| Write comment?
»
5 years ago, # |
  Vote: I like it +3 Vote: I do not like it

that's a normal segtree, i hope this help you.

»
5 years ago, # |
  Vote: I like it +4 Vote: I do not like it

article
I believe changing the '+='s to '='s is enough

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    That won't help in lazy propogation.

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      it should... when updating, push down before setting new value and when querying, make sure topmost change takes preference. shouldn't this be enough?

      • »
        »
        »
        »
        5 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Yes, it is enough. I dont know why he is saying it is not enough. Maybe he just doesnt know ...

      • »
        »
        »
        »
        5 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        it shouldn't in the classic way because you need a state of no propagation which is 0 in case of +=, in this case all numbers are valid propagation so he needs to add like a bool parameter to know if he needs to propagate or a number that can't be in the input.

        • »
          »
          »
          »
          »
          5 years ago, # ^ |
          Rev. 2   Vote: I like it 0 Vote: I do not like it

          just initialize the lazy with a impossible value of updating, like -123456789. Then, check if lazy[node]==-123456789, if it is, return, otherwise, update. What is the problem?