Segment Tree
A Segment Tree is a tree data structure for answering range queries efficiently while supporting updates. Each node represents an interval of the underlying array and stores an aggregate such as sum, minimum, maximum, or greatest common divisor. With a suitable merge operation, both range queries and point updates can be performed in O(log n).
Build: O(n).
Point update: O(log n).
Range query: O(log n) for standard segment-tree operations.
Uses O(n) memory, commonly around 4n for a recursive implementation.
Useful for dynamic range sum, min, max, and similar associative queries.