Common Mistakes

Common errors to avoid

  • Wrong tree size: Segment tree needs up to 44n nodes for safety. 2n might not suffice for all indices.
  • Incorrect range handling: Off-by-one errors in range queries are common. Carefully define inclusive/exclusive bounds.
  • Forgetting to propagate lazy updates: With lazy propagation, must push updates down before querying children.
  • Integer overflow in sums: Large arrays with large values can overflow.

Use long integers.