Range chmin (ai = min(ai, x)) with range sum / max. Each node shows max1 / max2 / cnt. The three-way rule: break when x ≥ max1, tag (O(1)) when max2 < x < max1, recurse when x ≤ max2.
| Operation | Cost | Note |
|---|---|---|
| Build | O(n) | same as any segment tree |
| Range max / sum query | O(log n) | plain query on max1 / sum |
| chmin (chmin + max) | amortized O(log n) | per-op unbounded; total O((n+q)log n) |
| chmin (chmin + sum) | amortized O(log² n) | sum maintenance adds a log |
| Space | O(n) | 4n nodes, 4 fields each |