Segment Trees & BIT

Lazy propagation, segment tree beats, and Fenwick tree applications through 10 problems.

46 lessons
159 min

Lessons

1. Introduction to Segment Trees and BIT

Range queries and updates

2m

2. Techniques Overview

What you'll learn

3m

3. Codeforces 380C Sereja and Brackets - Problem Statement

CF 380C - bracket subsequence queries

3m1 problems

4. Codeforces 380C Sereja and Brackets - Solution

Custom merge function

3m

5. Codeforces 380C Sereja and Brackets - Implementation

Build and query with custom merge

5m1 problems

6. Codeforces 380C Sereja and Brackets - Example and Complexity Analysis

Standard segment tree bounds

3m

7. Codeforces 52C Circular RMQ - Problem Statement

CF 52C - range min with circular queries

3m1 problems

8. Codeforces 52C Circular RMQ - Solution

Handle circular with two queries

3m

9. Codeforces 52C Circular RMQ - Implementation

Lazy propagation template

5m1 problems

10. Codeforces 52C Circular RMQ - Example and Complexity Analysis

Logarithmic with lazy

3m

11. Codeforces 558E A Simple Task - Problem Statement

CF 558E - sort substrings

3m1 problems

12. Codeforces 558E A Simple Task - Solution

One segment tree per letter

3m

13. Codeforces 558E A Simple Task - Implementation

26 trees with lazy assignment

5m1 problems

14. Codeforces 558E A Simple Task - Example and Complexity Analysis

26 times log factor

3m

15. Codeforces 914D Bash and a Tough Math Puzzle - Problem Statement

CF 914D - GCD range queries

3m1 problems

16. Codeforces 914D Bash and a Tough Math Puzzle - Why Naive Fails

Linear GCD is too slow

3m

17. Codeforces 914D Bash and a Tough Math Puzzle - Solution

Count bad elements

3m

18. Codeforces 914D Bash and a Tough Math Puzzle - Implementation

GCD segment tree with counting

5m1 problems

19. Codeforces 914D Bash and a Tough Math Puzzle - Example and Complexity Analysis

Logarithmic with early exit

3m

20. Codeforces 446C DZY Loves Fibonacci Numbers - Problem Statement

CF 446C - add Fibonacci to range

3m1 problems

21. Codeforces 446C DZY Loves Fibonacci Numbers - Why Naive Fails

Adding element by element is slow

3m

22. DZY Loves Fibonacci Numbers - Key Insight

Fibonacci sequence properties for lazy propagation

3m

23. Codeforces 446C DZY Loves Fibonacci Numbers - Solution

Store first two Fibonacci terms

3m

24. Codeforces 446C DZY Loves Fibonacci Numbers - Implementation

Lazy with Fibonacci pairs

5m1 problems

25. Codeforces 446C DZY Loves Fibonacci Numbers - Example and Complexity Analysis

Logarithmic with math

3m

26. Codeforces 438D The Child and Sequence - Problem Statement

CF 438D - modulo range update

3m1 problems

27. Codeforces 438D The Child and Sequence - Solution

Track maximum to skip

3m

28. Codeforces 438D The Child and Sequence - Implementation

Segment tree beats template

5m1 problems

29. Codeforces 438D The Child and Sequence - Example and Complexity Analysis

Amortized logarithmic

3m

30. Codeforces 459D Pashmak and Parmida's problem - Problem Statement

CF 459D - count inversions of frequencies

3m1 problems

31. Codeforces 459D Pashmak and Parmida's problem - Solution

BIT for inversion counting

3m

32. Codeforces 459D Pashmak and Parmida's problem - Implementation

BIT for counting inversions

5m1 problems

33. Codeforces 61E Enemy is weak - Problem Statement

CF 61E - count decreasing triples

3m1 problems

34. Codeforces 61E Enemy is weak - Solution

Two BITs for left and right counts

3m

35. Codeforces 61E Enemy is weak - Implementation

Coordinate compression and two passes

5m1 problems

36. Codeforces 540E Infinite Inversions - Problem Statement

CF 540E - inversions after swaps

3m1 problems

37. Codeforces 540E Infinite Inversions - Why Naive Fails

Infinite positions

3m

38. Infinite Inversions - Key Insight

Gap contribution for unchanged positions

3m

39. Codeforces 540E Infinite Inversions - Solution

Compress and count gaps

3m

40. Codeforces 540E Infinite Inversions - Implementation

Handle gaps between affected positions

5m1 problems

41. Codeforces 540E Infinite Inversions - Example and Complexity Analysis

Based on swap count

3m

42. Codeforces 474E Pillars - Problem Statement

CF 474E - longest subsequence with gap constraint

3m1 problems

43. Codeforces 474E Pillars - Solution

Segment tree for range max DP

3m

44. Codeforces 474E Pillars - Implementation

Segment tree range max queries

5m1 problems

45. Quiz: Segment Trees and BIT

Test your understanding

5m1 problems

46. Section Recap

What you've learned

3m

Ready to start learning?

Access all 46 lessons with interactive content and progress tracking.