segment tree

SPOJ Problem Set (classical) - Horrible Queries

segment tree divide and conquer spoj

Problem: Please find the problem here. Solution: Using the segment tree like in SPOJ_LITE_2. This time the summary is the sum instead of on light count, but it is just as easy to update those summaries. Code:

SPOJ Problem Set (classical) - Light switching (2nd attempt)

segment tree divide and conquer spoj

Problem: Please find the problem here. Solution: After doing some optimization - the previous solution still cannot be accepted - need to try something else. Previously I was worried about memory consumption creating a full blown segment tree by virtualizing the segments. What if I just create it? Again, we consider this simple example of inserting the segment [1, 5] and [3, 7] Initially the tree is completely empty. 00000000000000 Now we insert [1, 5]