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 666 / 680 1400
Point update, minimum query 591 / 618 1400
Range update, sum query 552 / 588 1400
Range update, minimum query 510 / 525 1400
Apple picking 321 / 390 1500
Non-negative subarray 333 / 372 1500
Inversions 301 / 307 1500
K-query 330 / 347 1500
Divisible by 3 300 / 325 1500
Mushroom harvesting 176 / 188 1500
KSS 171 / 212 1500
D-query 260 / 282 1600
Greatest subarray sum 231 / 248 1600
Copying data 156 / 163 1600
Within 1 153 / 178 1600
Within 2 144 / 158 1600
Ladder update 159 / 175 1700
Racing 87 / 97 1700
One time 113 / 133 1800
Subarray XOR 109 / 116 1800
String sorting 103 / 137 1900
Odd query 34 / 57 2000
Full sequence 20 / 28 2000