Editorial for Bubble Cup V9 G Heroes of Making Magic III
Submitting an official solution before solving the problem yourself is a bannable offence.
For queries of type 2, we are only interested in the elements
It can be easily seen that in order to clear a segment, we can just move back and forth between positions
(since we have to decrease the first element of the segment in the first step) (after following this procedure, is decreased exactly by , and we end up on ) , or, , …- In general,
has to be greater or equal to , if is odd, and , if is even
Equivalently, if we define a new sequence
Of course, we do not have to store the
- For even values of
, - For odd values of
,
Now we only need a way to maintain the array
- Elements on even positions inside the interval
are increased by - If
is even, elements on positions are decreased by , and elements on positions are increased by
All of this can be derived from our definition of
Both of these queries can be efficiently implemented using a lazy-propagation segment tree, where each internal node stores two numbers, the minimal of its odd- and even-indexed leaves.
Using the approach described above, we arrive at a solution with the complexity of
Comments