Iarcs BOOKLIST problem

I have been trying BOOKLIST Contest Page | CodeChef question for a while but i am only able to fetch 60 points. I am using vectors to insert and erase elements. But because of complexity of erase,O(N), I am getting TLE. Can someone point me in the right direction. Is their some standard algorithm to solve these types of questions??
Here is my code: DVv5CN - Online C++ Compiler & Debugging Tool - Ideone.com

Thanks.

1 Like

The hint i would suggest for this problem would be to think about sorting the set of book already issued.Here is the link to solved problem:zjshg7 - Online C++ Compiler & Debugging Tool - Ideone.com
ask me if any further doubts arises.

1 Like

seems like segment tree will be used

Great!! It works…
Logic is clear too…
Thanks&&Cheers

i was also thinking about using segment trees but got lost. Do you have some idea?

each node stores the number of books that are not yet borrowed in the segment.

can someone please explain this problem to me, i can’t seem to getting this problem