I have no idea how to solve this:
http://acm.sgu.ru/problem.php?contest=0&problem=311
Please help me with this one
I know it can be solved using segment tree but I don’t know how
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Read all of the prices and set up a segment tree. For each segment, store the number and total cost of pieces whose prices lie in that segment. That’s most of the problem, and the rest of this answer will be rather vague in hopes that you learn something.
Handling an arrival of pieces is a straightforward O(log n)-time descent in the segment tree.
Handling a purchase request is also an O(log n)-time descent followed by an update if a sale was made. The update may traverse a large amount of the segment tree and is fast only in an amortized sense – an interval should be entered if and only if there are pieces in that price range, and the running time of their removal should be charged to the arrival.