divide and conquer

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]

SPOJ Problem Set (classical) - Light switching (1st attempt)

divide and conquer avl tree spoj

Problem: Please find the problem here. Solution: This problem is really a hard nut to crack. I know there exist simpler solution, but I am going with my idea and implement that complex idea first. The goal is, really, to prove to myself that my idea works, and that to practice coding and debugging complex algorithm. It all started with some simple observations. Judging from the numbers, I believe we can’t allow update to take time proportional to the interval length, or otherwise one could easily construct an example to just keep flipping the whole interval and we are screwed with awful performance.