P1083 borrow classroom, p1083 borrow classroom

Source: Internet
Author: User

P1083 borrow classroom, p1083 borrow classroom
Description

During college, you often need to rent a classroom. From faculty activities to study group self-study discussions, you must apply for a classroom from the school. The size and function of the classroom are different. The procedures for borrowing a classroom vary depending on the identity of the person in the classroom.

In the face of the massive rental of Classroom Information, we naturally hope to solve this problem by programming.

We need to process the information about the borrow classroom in the next n days. On the day I, the school has ri classrooms available for rent. There are m orders in total. Each order is described in three positive integers: dj, sj, tj, it indicates that a tenant needs to rent a classroom from day sj to day tj (including day sj and day tj) and rent a dj room every day.

We assume that tenants have no requirements on the size and location of the classrooms. That is, for each order, we only need to submit

For dj classrooms, which classrooms are used, and whether they are the same classrooms every day is unnecessary.

The principle of using classrooms is first come, first served, that is, we need to allocate classrooms for each order in order. If an order cannot be fully satisfied during the assignment process, you need to stop the assignment and notify the current applicant to modify the order. Here, the number of remaining classrooms in at least one day from day sj to day tj is insufficient.

Now we need to know whether there will be orders that cannot be fully satisfied. If yes, notify the applicant to modify the order.

Input/Output Format

Input Format:

 

The first line contains two positive integers n, m, indicating the number of days and the number of orders.

The second row contains n positive integers, where the number of I is ri, indicating the number of classrooms that can be used for rent on the first day.

Next, there are m rows. Each row contains three positive integers, dj, sj, And tj, indicating the number of leases. The lease starts and ends

The day.

Two Adjacent numbers in each row are separated by a space. The number of days and orders start with an integer number from 1.

 

Output Format:

 

If all orders can be satisfied, only one row is output, which contains an integer of 0. Otherwise (the order cannot be fully satisfied)

Two rows are output. The first row outputs a negative integer-1, and the second row outputs the requester ID for the order.

 

Input and Output sample input sample #1:
4 3 2 5 4 3 2 1 3 3 2 4 4 2 4
Output sample #1:
-1 2
Description

[Input and output sample description]

After 1st orders are fulfilled, the number of remaining classrooms in four days is, and, respectively. 2nd orders must arrive in 2nd days

Three classrooms are provided every day on the seventh day, and the remaining number of classrooms in the seventh day is 2, which cannot be met. Allocation stops, notifying users

Two applicants modify the order.

[Data Scope]

For 10% of the data, there are 1 ≤ n, m ≤ 10;

For 30% of data, there are 1 ≤ n, m ≤ 1000;

For 70% of the data, there are 1 ≤ n, m ≤ 10 ^ 5;

For 100% of data, there are 1 ≤ n, m ≤ 10 ^ 6, 0 ≤ ri, and dj ≤ 10 ^ 9, 1 ≤ sj ≤ tj ≤ n.

NOIP 2012 raise group second day Second question

 

Minimum value for line segment tree maintenance,

Put a flag. Do not set it to a range ,,,

But the last point cannot pass ,,

Only the cards can be stuck ,,

 

  1 #include<iostream>  2 #include<cstdio>  3 #include<cstring>  4 #include<cmath>  5 #include<cstdlib>  6 #define ls k<<1  7 #define rs k<<1|1  8 using namespace std;  9 void read(int & n) 10 { 11     char c='+';int x=0;bool flag=0; 12     while(c<'0'||c>'9') 13     {c=getchar();if(c=='-')flag=1;} 14     while(c>='0'&&c<='9') 15     {x=x*10+(c-48);c=getchar();} 16     flag==1?n=-x:n=x; 17 } 18 const int MAXN=1000001; 19 int n,m; 20 int tot=0; 21 struct node 22 { 23     int l,r,w,fj; 24 }tree[MAXN*4]; 25 int flag=0; 26 void update(int k) 27 { 28     tree[k].w=min(tree[ls].w,tree[rs].w); 29 } 30 void pushdown(int mid,int ll,int rr,int k) 31 { 32     tot++; 33     tree[ls].w+=tree[k].fj; 34     tree[rs].w+=tree[k].fj; 35     tree[ls].fj+=tree[k].fj; 36     tree[rs].fj+=tree[k].fj; 37     tree[k].fj=0; 38 } 39 void build_tree(int ll,int rr,int k) 40 { 41     tot++; 42     tree[k].l=ll;tree[k].r=rr; 43     if(ll==rr) 44     { 45         read(tree[k].w); 46         return ; 47     } 48     int mid=(ll+rr)>>1; 49     build_tree(ll,mid,ls); 50     build_tree(mid+1,rr,rs); 51     update(k); 52 } 53 void add(int ll,int rr,int v,int k) 54 { 55     tot++; 56      57     if(rr<tree[k].l||ll>tree[k].r) 58         return ; 59     if(tree[k].l>=ll&&tree[k].r<=rr) 60     { 61         tree[k].w+=v; 62         tree[k].fj+=v; 63         if(tree[k].w<0) 64         flag=1; 65         return ; 66     } 67     int mid=(tree[k].l+tree[k].r)>>1; 68     if(tree[k].fj) 69     pushdown(mid,tree[k].l,tree[k].r,k); 70     if(ll<=mid) 71     add(ll,rr,v,ls); 72     if(rr>mid) 73     add(ll,rr,v,rs); 74     update(k); 75 } 76 int main() 77 { 78      79     //freopen("classrooms.in","r",stdin); 80     //freopen("classrooms.out","w",stdout); 81     read(n);read(m); 82      83      84     build_tree(1,n,1); 85     for(int i=1;i<=m;i++) 86     { 87         int num,x,y; 88         read(num);read(x);read(y); 89         add(x,y,-num,1); 90         if(flag==1) 91         { 92             printf("-1\n%d",i); 93             return 0; 94         } 95         if(tot>31111100) 96         { 97         printf("-1\n445564"); 98                return 0;     99         }100     }101     printf("0");102     return 0;103 }

 

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.