Noip2012-day2-t2

Source: Internet
Author: User

"Problem description"

It is often necessary to rent a classroom during college. Large to the Department to organize activities, small to study group discussion, all need to apply to the school to borrow the classroom. The classroom size function is different, borrows the classroom person's identity to be different, borrows the classroom The procedure also is dissimilar.
In the face of the vast amount of information rented classrooms, we naturally want to program to solve this problem.
We need to deal with the next n days of borrowing classroom information, where I day school has RI classrooms available for rent. A total of M orders, each order with three positive integer description, respectively, DJ, SJ, TJ, indicating that a renter from SJ to TJ days to rent a classroom (including SJ Day and TJ Days), daily need to rent a DJ classroom.
We assume that the renter has no requirement for the size and location of the classroom. That is, for each order, we only need to provide a DJ classroom every day, and they are specific classrooms, whether the same classroom every day is not considered.
The principle of borrowing a classroom is first come first served, that is, we have to assign the classroom to each order in order. If you encounter an order that cannot be fully met during the allocation process, you will need to stop the classroom assignment and notify the current applicant to modify the order. The inability to meet here means that the number of classrooms remaining at least one day from the day of SJ to TJ is less than a DJ.
Now we need to know if there will be an order that is not fully satisfied. If so, which applicant needs to be notified to modify the order.

Solution

For this problem we need to use the dichotomy and prefix and. For each order, we have three numbers s,t,d we use an array sum to store the prefix and. If there are five days, the first sum array is "0,0,0,0,0" when s=2,t=4,d=2. We do this operation Sum[s]+=d;sum[t+1]-=d, so that sum becomes "0,2,0,0,-2" and then we ask for the prefix and sum to become "0,2,2,2,0" We have completed a record of two classrooms that need to be borrowed from the second day to the fourth day. Think of here, we just need to use the dichotomy, two points before a few orders, and then we check to see whether the first X orders every day of the classroom is enough, and finally can be two points to get the answer. PS: This problem can also be solved with a segment tree, but use the lazy tag.

Noip2012-day2-t2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.