Segment tree
Segment tree
A segment tree (Segment Tree) is a data structure for quickly answering queries on a subsegment of an array and updating elements.
Usually used for queries like:
- sum on a segment
- minimum / maximum on a segment
- and other associative operations
Idea
There is an array .
We build a binary tree where:
- each node stores a value for some segment
- the root stores the value for the entire array