TYVJ 2075 [noip2012t5] Borrow classroom interval update + two points

Source: Internet
Author: User

Description during college, it is often necessary to rent a classroom. 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 Day 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. Input format input file is classroom.in.
The first line contains two positive integer n,m, representing the number of days and orders.
The second line contains n positive integers, where the number of I is RI, which indicates the number of classrooms that can be used for lease on day I.
Next there are m lines, each containing three positive integer DJ,SJ,TJ, indicating the number of leases, the start of the lease, and the end of the day respectively.
Each row is separated by a space between the two numbers that are adjacent to each other. The number of days and orders is numbered with an integer starting from 1. Output format output file is classroom.out.
If all orders are satisfied, the output is only one row and contains an integer 0. Otherwise (the order cannot be fully satisfied) outputs two lines, the first line outputs a negative integer-1, and the second line outputs the applicant number to modify the order. Test Sample 1 input
4 3
2 5 4 3
2 1 3
3 2 4
4 2 4
Output
-1
2
Note For 10% of the data, there is 1≤n,m≤10;
For 30% of the data, there are 1≤n,m≤1000;
For 70% of the data, there are 1≤n,m≤10^5;
For 100% of the data, there is 1≤n,m≤10^6,0≤ri,dj≤10^9,1≤sj≤tj≤n. Idea: (line tree t don't want, it is said that zkw line tree can a, unfortunately not) because it is the interval, you can add that value at the beginning of the interval, the end +1 minus that value, accumulate, do not say imaginative achievement here, see Code;
#include <iostream>#include<cstdio>#include<cmath>#include<string>#include<queue>#include<algorithm>#include<stack>#include<cstring>#include<vector>#include<list>#include<Set>#include<map>using namespacestd;#definell __int64#defineMoD 1000000007intScan () {intres =0, ch;  while( ! (ch = getchar ()) >='0'&& CH <='9' ) )    {        if(ch = = EOF)return 1<< - ; } Res= CH-'0' ;  while(ch = getchar ()) >='0'&& CH <='9') Res= Res *Ten+ (CH-'0' ) ; returnRes;}intans[1000010];inta[1000010],x;struct  is{    intL,r,change;} t[1000010];intCheckintk) {memset (ans,0,sizeof(ans));  for(intI=1; i<=k;i++) {ANS[T[I].L]+=T[i].change; ANS[T[I].R+1]-=T[i].change; }    intsum=0;  for(intt=1; t<=x;t++) {sum+=Ans[t]; if(sum>A[t])return 0; }    return 1;}intMain () {intY,z,i; scanf ("%d%d",&x,&y);  for(i=1; i<=x;i++) scanf ("%d",&A[i]);  for(i=1; i<=y;i++) scanf ("%d%d%d",&t[i].change,&t[i].l,&T[I].R); intst=1; inten=y; intMid= (St+en) >>1;  while(st<en) {Mid= (St+en) >>1; if(check (mid)) St=mid+1; Elseen=mid; }    if(for Check (ST)) printf ("0\n"); Elseprintf ("-1\n%d\n", ST); return 0;}
View Code

TYVJ 2075 [noip2012t5] Borrow classroom interval update + two points

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.