Segment Tree
Segment Tree
A Segment Tree is an advanced data structure that allows you to efficiently perform range queries and point updates on an array — operations that would take O(n) per query with brute force, reduced to O(log n) with a Segment Tree.
Video Explanation

🧠 Why Segment Tree?
Problem: Given array [1, 3, 5, 7, 9, 11]
Answer Q queries: "What is the sum of elements from index L to R?"
Also handle U updates: "Change element at index i to value v"
❌ BRUTE FORCE:
Query: O(n) per query → 100 queries on 10⁶ array = 10⁸ operations (TLE)
Update: O(1)
✅ SEGMENT TREE:
Build: O(n)
Query: O(log n)
Update: O(log n)