Please help me understand the ForbiddenSum problem.

binary-search
jan14
segment-tree

#1

Hi fellas. I am having tough time understanding the solution to this problem. It has a editorial. Although from editorial approach is quite clear, but when I try to read the code of the author, I don’t quite understand it. Points I specifically don’t understand in the authors solution are following:

  1. How is the segment tree being constructed.
  2. What is the purpose of the “Root” array.
  3. And in the “rect” function, why “res” is chosen that way. I mean like upper_bound function of C++.

Other quite good/readable solution, I found was of the user @deneo, here, he also did the same thing.
Please help me!!!

Thnx


#2

This question can violate the rules of ongoing contest. Hence, we cannot help you. But try doing some hand-work, and construct the segment tree and apply the approach. You’ll get it else you’ll have to wait till the contest ends. :slight_smile:


#3

I get it. yea sure, I guess I have to try bit harder.