Prerequisites

What you need first

You need strong understanding of recursion and binary trees. Segment trees support range queries (like sum, min, max over a range) and point updates, both in O(logn)O(\log n) time. They're built by recursively dividing the array.

This is an advanced data structure. Complete easier tree problems first. Each node stores aggregate information for its segment. Queries combine information from O(logn)O(\log n) non-overlapping segments that cover the query range.