Editorial for Figurines
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
We use a lazy segment tree. This data structure will not be discussed in detail as other resources can be found on this data structure.
For each node, we store a variety of values. bestA
and bestB
store the best and values, respectively. best
is the best value.
We do standard lazy segment tree updates and queries. The only important operation to discuss is the lazy propagation.
Let us first consider propagating a lazy set operation (type A). The other operation (type B) is the max operation. We can propagate these in either order.
For propagating an operation of type A, let the number we are setting everything to be . Note that since all the values are the same, . Thus, . This is the easier operation.
For propagating an operation of type B, let the number we are using be . Now obviously, . However, how are we to update ?
We note that the new best has two options. One option is . This is quite obvious since each B value is now at least . The second option is the previous value of . The second case is if there exists a position where and . The reason is that this operation will not decrease . Thus, if changes, it will be equal to , since each B item is at least . Otherwise, stays just as it was before.
Note that the values for and can be zero, so you have to store a boolean to keep track of laziness (sorry not sorry).
P.S. This problem was inspired by my attempts at Tourism. I knew of a monotonic solution but it didn't click with me, so I just developed a new data structure instead. When in doubt, bash it with DS!
Comments