Segment trees work for any associative operation with an identity element: | Operation | Merge | Identity | |-----------|-------|----------| | Sum | | | | Min | | | | Max | | | | Product | | | | GCD | | | | XOR | | | | AND | | all 1s | | OR | | | The key requirement: (associativity).
For non-associative operations (like median), segment trees don't directly work. You'd need to store more information at each node.