0PricingLogin
Competitive Programming Academy · Lesson

Segment Tree: Build & Query

Range min, max, or sum in log n.

Beyond the Fenwick Tree

A Fenwick tree shines for sums, but a segment tree handles min, max, gcd, and more. It is the flexible workhorse of range queries.

A Tree Over Ranges

Each node owns a range of the array. The root covers everything; children split it in half until leaves hold single elements.

All lessons in this course

  1. Fenwick Tree for Prefix Sums
  2. Inversions with a BIT
  3. Segment Tree: Build & Query
  4. Lazy Propagation for Range Updates
← Back to Competitive Programming Academy