Comments
+2

My dream is to be an expert, and the day I have the opportunity, you destroy my dream :(

It can be solved using a segment tree :)

Nice code bro.

I wrote the problem in Portuguese without translation, if you want I can share the link

I know that. I'm the author of the problem, so I just wanted to mention one of the simplest ways to solve it.

You can solve this problem with O(log(n)²) per query. Just make a binary search over X and use a BIT (Segtree, whatever) to determine how many elements are bigger than X, with this you can determine if you have to go left or right.

You can do better using just a SegTree.

On my machine it worked for both cases. Look this case, your code doesn't work: 1 2 91125426 911

I got it, thanks !

Where I can find the option "Audit only" for the other 4 courses ?

Thank's, my mistake was: Overflow, I changed my variables to long long and acc.

Thank you, but you know where is my mistake ?

I didn't understand, my mistake is here ?

if(L != R)
{
   lazy[left(p)] += newValue;
   lazy[right(p)] += newValue;
}

My code was based on this: http://www.geeksforgeeks.org/lazy-propagation-in-segment-tree/ Is it wrong too ?