1291 train lines, 1291 lines

Source: Internet
Author: User

1291 train lines, 1291 lines
Time Limit: 1 s space limit: 128000 KB title level: MasterQuestionView running resultsDescriptionDescription

A train runs between cities C (the departure city number is 1 and the end city number is C). Suppose the train has S seats, there are now R pre-booking services. Now I want to process this R business and see which reservations can meet and which cannot meet the requirements.

A reservation consists of three integers: O, D, and N, indicating that N seats are required from the start station O to the target Station D. A reservation is an empty seat that can be satisfied by the business within the itinerary. Otherwise, it cannot be satisfied. A business cannot be split, that is, the starting point and the terminal cannot be changed, and the number of reserved seats cannot be changed. All the predefined requirements are processed in the order given.

Please write a program to see if the pre-defined business can meet those requirements.

Input description Input Description

Input FileThe first action in three IntegersC,S,R,(1 <=C<= 60 000, 1 <=S<= 60 000, 1 <=R<= 60 000)They are separated by an empty gap. NextREach row has three integers.O, D, N, (1 <=O<D<=C, 1 <=N<=S), Indicating each predefined business.

Output description Output Description

For business I, if yesMediumOutput "T" in line I; otherwise, output "N"

Sample Input Sample Input
4 6 4
1 4 2
1 3 2
2 4 3

1 2 3

Sample output Sample Output
T
T
N

N'

'The mmzz question is poisonous...

It is the minimum value of a bare line segment tree record.

He misunderstood his question ,.

Adjusted for three hours

  1 #include<iostream>  2 #include<cstdio>  3 #include<cstring>  4 #include<cmath>  5 #include<queue>  6 #include<algorithm>  7 #define ls k<<1  8 #define rs k<<1|1  9 using namespace std; 10 const int MAXN=2000001; 11 void read(int &n) 12 { 13     char c='+';int x=0;bool flag=0; 14     while(c<'0'||c>'9') 15     {c=getchar();if(c=='-')flag=1;} 16     while(c>='0'&&c<='9') 17     {x=x*10+c-48,c=getchar();} 18     flag==1?n=-x:n=x; 19 } 20 int n,m,chair; 21 int ans=-1; 22 struct node 23 { 24     int l,r,w,fm; 25 }tree[MAXN*4]; 26 void update(int k) 27 { 28     tree[k].w=min(tree[ls].w,tree[rs].w); 29      30 } 31 void pushdown(int k) 32 { 33     tree[ls].w-=tree[k].fm; 34     tree[rs].w-=tree[k].fm; 35     tree[ls].fm+=tree[k].fm; 36     tree[rs].fm+=tree[k].fm; 37     tree[k].fm=0; 38     //cout<<"ls:"<<(ls)<<" "<<tree[ls].w<<" "; 39     //cout<<"rs:"<<(rs)<<" "<<tree[rs].w<<" "<<endl; 40 } 41 void build_tree(int ll,int rr,int k) 42 { 43     tree[k].l=ll;tree[k].r=rr; 44     if(ll==rr) 45     { 46         tree[k].w=chair; 47         return ; 48     } 49     int mid=(ll+rr)>>1; 50     build_tree(ll,mid,ls); 51     build_tree(mid+1,rr,rs); 52     update(k); 53 } 54 void interval_ask(int ll,int rr,int num,int k) 55 { 56     if(ll>tree[k].r||rr<tree[k].l) 57         return ; 58     if(ll<=tree[k].l&&tree[k].r<=rr) 59     { 60         if(tree[k].w<num) 61             ans=-1; 62         return ; 63     } 64     int mid=(tree[k].l+tree[k].r)>>1; 65     if(tree[k].fm) 66     pushdown(k); 67     if(ll<=mid) 68     interval_ask(ll,rr,num,ls); 69     if(rr>mid) 70     interval_ask(ll,rr,num,rs); 71     if(tree[k].fm) 72     pushdown(k); 73 } 74 void point_change(int pos,int v,int k) 75 { 76     if(pos>tree[k].r||pos<tree[k].l) 77         return ; 78     if(tree[k].l==tree[k].r) 79     { 80         tree[k].w=v; 81         return ; 82     } 83     point_change(pos,v,ls); 84     point_change(pos,v,rs); 85     update(k); 86 } 87  88 void interval_change(int ll,int rr,int num,int k) 89 { 90     if(ll>tree[k].r||rr<tree[k].l) 91         return ; 92     if(ll<=tree[k].l&&rr>=tree[k].r) 93     { 94         tree[k].w-=num; 95         tree[k].fm+=num; 96         return ; 97     } 98     int mid=(tree[k].l+tree[k].r)>>1; 99     if(tree[k].fm)100     pushdown(k);101     if(ll<=mid)102     interval_change(ll,rr,num,ls);103     if(rr>mid)104     interval_change(ll,rr,num,rs);105     update(k);106 }107 int main()108 {109     read(n);read(chair);read(m);110     build_tree(1,n,1);111     for(int i=1;i<=m;i++)112     {113         int l,r,num;114         ans=1;115         read(l);read(r);read(num);116         r--;117         interval_ask(l,r,num,1);118         if(ans!=1)119             printf("N\n");120         else 121         {122             interval_change(l,r,num,1);123             printf("T\n");    124         }125     }126     return 0;127 } 

 

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.