Module Introduction to Segment Tree and Binary Indexed Tree

Introduction to Segment Tree and Binary Indexed Tree

**Frequency: 10/10** Segment trees and binary indexed trees (BIT) are indispensable data structures in competitive programming, enabling efficient range queries and updates over arrays. Generally speaking, Segment Tree is more versatile while BIT have a lower constant factor. Since BIT can be a bit tricky to understand at first, most people choose to start with Segment Tree. And you should choose Segment Tree too.

Resources

- [CP Algorithms: Segment Tree](https://cp-algorithms.com/data_structures/segment_tree.html) - [CP Algorithms: Fenwick Tree](https://cp-algorithms.com/data_structures/fenwick.html)

Problems

Point update, sum query 481 / 491 1400
Point update, minimum query 428 / 448 1400
Range update, sum query 393 / 420 1400
Range update, minimum query 368 / 375 1400
Apple picking 228 / 278 1500
Non-negative subarray 228 / 266 1500
Inversions 213 / 220 1500
K-query 241 / 253 1500
Divisible by 3 223 / 246 1500
Mushroom harvesting 123 / 133 1500
KSS 109 / 134 1500
D-query 182 / 203 1600
Greatest subarray sum 164 / 179 1600
Copying data 106 / 112 1600
Within 1 109 / 121 1600
Within 2 102 / 113 1600
Ladder update 112 / 126 1700
Racing 62 / 70 1700
One time 74 / 91 1800
Subarray XOR 77 / 82 1800
String sorting 71 / 97 1900
Odd query 22 / 31 2000
Full sequence 7 / 9 2000