noip2012-day2-t2

Original link: http://www.cnblogs.com/hyl2000/p/5850947.html

【Problem Description】

  In college, often you need to rent classroom. Large departments to organize activities, small study groups to discuss self-study, we need to apply to the school by the classroom. Different functions classroom size, classroom by people of different identities, by classroom procedures are not the same.
The face of massive loan information classroom, we naturally want to program to solve this problem.
We need to deal with the next n days by classroom information, where the first day of school i ri classrooms available for rental. M total parts orders, each order is described by three positive integers, respectively, DJ, sj, tj, indicates a need to lease from the lease class sj tj day to day (Day sj tj including the first day), per day dj needs to rent classrooms.
  We assume that there is no requirement for renters classroom size, location. That is, for each order, we only need to provide a day dj classrooms, and what are their specific classroom, every day is the same whether the classroom is not considered.
By the principle of the classroom is first come first served, which means that we have to follow the order of the order of each order were assigned classrooms. If you have an order can not be completely satisfied in the process of allocation, we need to stop distribution of the classroom, notify the applicant to modify the current orders. Here refers not meet at least one day remaining classrooms from sj tj day to day in an insufficient number one dj.
  Now we need to know, whether there will be order can not be fully met. If so, which one needs to inform the applicant to modify the order.

【solution】

  This question and we need to use the prefix and the dichotomy. For each order, we have three numbers s, t, d we use a storage array sum and prefix. If five days, beginning 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; this becomes a sum {0,2,0,0, -2} Then we seek prefix and the sum becomes [ 0,2,2,2,0] we have completed the recording of the second day to the fourth day need to borrow two classrooms. Thought of this, we only need to use the back dichotomy, several orders-half ago, and then we check it to see whether the first x orders a day are enough classrooms, finally able to get half the answer. ps: This problem can also be solved with a tree line, but you want to use lazy mark.

Reproduced in: https: //www.cnblogs.com/hyl2000/p/5850947.html

Guess you like

Origin blog.csdn.net/weixin_30954265/article/details/94785405