Beats And Second Maximum

Segment tree beats supports range chmin alongside range sum. What tag does each node keep, and where does the recursion stop?

A

Maximum, a lazy add tag, and the count of maxima. chmin(l,r,x) stops when x≥max⁡x \ge \max (nothing changes) or when the node is fully covered (the tag absorbs it, so the sum shifts by len⋅(x−max⁡)len \cdot (x - \max)). It recurses only when it is partly covered, which makes it O(log⁡n)O(\log n) worst case.

B

Maximum, strict second maximum, and the count of maxima. chmin(l,r,x) stops when x≥max⁡x \ge \max (nothing changes) or when secondmax<x<max⁡secondmax < x < \max (only the maxima move, so the sum shifts by cnt⋅(x−max⁡)cnt \cdot (x - \max)). It recurses only when x≤secondmaxx \le secondmax.

C

Maximum, minimum, and the count of maxima. chmin(l,r,x) stops when x≥max⁡x \ge \max (nothing changes) or when min⁡<x<max⁡\min < x < \max (only the maxima move, so the sum shifts by cnt⋅(x−max⁡)cnt \cdot (x - \max)). It recurses only when x≤min⁡x \le \min.

D

Maximum, strict second maximum, and the count of maxima. chmin(l,r,x) stops when x≤max⁡x \le \max (nothing changes) or when secondmax<x<max⁡secondmax < x < \max (all elements move, so the sum shifts by len⋅(x−max⁡)len \cdot (x - \max)). It recurses only when x≥secondmaxx \ge secondmax.