1593: [Usaco2008 Feb]hotel Hostel

Source: Internet
Author: User

1593: [Usaco2008 Feb]hotel hostel Time limit:10 Sec Memory limit:64 MB
submit:489 solved:272
[Submit] [Status] [Discuss] Description

The most recent travel plan for cows is to Lake Superior and enjoy the mountains and lakes and the bright sunshine. As the planner and head of the entire tour, Bessie chooses to stay at a famous hotel on the lake side. This huge hotel has a total of n (1 <= N <= 50,000) rooms, which are lined up sequentially in the same floor, in any room, just open the curtains and you will see the sparkling lake. Bessie's line, and other tourists, were a batch of land to the hotel's desk, hoping to book a continuous room between d_i (1 <= d_i <= N). Reception work at the reception desk is also simple: if there is an r that satisfies the number R. R+d_i-1 's room was empty, and he arranged this batch of customers to stay in these rooms, and if he did not meet the conditions of R, he would apologize for not having enough empty rooms, ask customers to find another hotel. If there are multiple r that meet the criteria, the waiter chooses the smallest one. The check-out service is also available in bulk in the hotel. Each check-out request is described by a 2 digit x_i, d_i, indicating that the number is x_i. X_i+d_i-1 (1 <= x_i <= n-d_i+1) All the guests in the room leave. Before check-out, some of the rooms that request a refund, or even all of them, may have been left unattended. And your job is to write a program to help the waiter arrange a room for the passengers. Your program will have to deal with M (1 <= m < 50,000) in-house or check-out requests arriving in the order of entry. All the rooms in the hotel were free before the first request arrived.

Input

* Line 1th: 2 integers separated by a space: N, M

* 2nd. M+1: Section i+1 describes the I request, if it is a reservation request, then with 2 numbers 1, d_i description, the numbers are separated by a space; if it is a check-out request, use 3 space-delimited numbers 2, x_i, d_i description

Output

* 1th ...?? Line: For each booking request, Output 1 exclusive 1 rows of numbers: If the request can be satisfied, the output satisfies the minimum r; If the request cannot be satisfied, the output 0

Sample Input10 6
1 3
1 3
1 3
1 3
2 5 5
1 6

Sample Output1
4
7
0
5
HINT Source

Usaco Gold

[Submit] [Status] [Discuss]

1#include <iostream>2#include <cstdio>3#include <cstdlib>4#include <cstring>5#include <algorithm>6#include <cmath>7 using namespacestd;8typedefLong LongLL;9 Const intmaxn=50010;Ten structnode{ One     intL,r; A     intLs,rs; -     intMaxlen,llen,rlen; -     intlazy; the}seg[maxn*Ten]; - intn,m; - inttot=1; - voidUpdata_down (intRT) { +     if(seg[rt].lazy==-1)return ; -     intD=Seg[rt].lazy; +     intLson=seg[rt].ls;intrson=seg[rt].rs; ASeg[lson].maxlen=seg[lson].llen=seg[lson].rlen= (seg[lson].r-seg[lson].l+1)*D; atSeg[rson].maxlen=seg[rson].llen=seg[rson].rlen= (seg[rson].r-seg[rson].l+1)*D; -seg[lson].lazy=seg[rson].lazy=Seg[rt].lazy; -seg[rt].lazy=-1; - } - voidUPDATA_UP (intRT) { -     intLson=seg[rt].ls;intrson=seg[rt].rs; inSeg[rt].maxlen=max (Seg[lson].maxlen,max (seg[rson].maxlen,seg[lson].rlen+Seg[rson].llen)); -     if(seg[lson].llen==seg[lson].r-seg[lson].l+1) seg[rt].llen=seg[lson].llen+Seg[rson].llen; to     Elseseg[rt].llen=Seg[lson].llen; +     if(seg[rson].rlen==seg[rson].r-seg[rson].l+1) seg[rt].rlen=seg[rson].rlen+Seg[lson].rlen; -     Elseseg[rt].rlen=Seg[rson].rlen; the } * voidBuild (intRtintLintR) { $Seg[rt].l=l; Seg[rt].r=R;Panax NotoginsengSeg[rt].maxlen=seg[rt].llen=seg[rt].rlen= (r-l+1); -seg[rt].lazy=-1; the     if(L==R)return ; +     intMid= (l+r) >>1; Atot++; seg[rt].ls=tot; Build (Seg[rt].ls,l,mid);  thetot++; Seg[rt].rs=tot; Build (seg[rt].rs,mid+1, R); + } - intQueryintRtintLen) { $ Updata_down (RT); $     intLson=seg[rt].ls;intrson=seg[rt].rs; -     if(Seg[rt].maxlen<len)return 0; -     if(seg[rt].r-seg[rt].l+1==len)returnSEG[RT].L; the     if(Seg[lson].maxlen>=len)returnquery (Lson,len); -     if(Seg[lson].rlen+seg[rson].llen>=len)returnseg[lson].r-seg[lson].rlen+1;Wuyi     returnquery (Rson,len); the } - voidChangeintRtintLintRintk) { Wu Updata_down (RT); -     if(l<=seg[rt].l&&seg[rt].r<=R) { AboutSeg[rt].maxlen=seg[rt].llen=seg[rt].rlen= (seg[rt].r-seg[rt].l+1)*K; $seg[rt].lazy=K; -         return ; -     } -     intLson=seg[rt].ls;intrson=seg[rt].rs; A     intMid= (SEG[RT].L+SEG[RT].R) >>1; +     if(l<=mid) Change (lson,l,r,k); the     if(mid+1<=r) Change (rson,l,r,k); - updata_up (RT); $ } the intMain () { thescanf"%d%d",&n,&M); theBuild (1,1, N); the     intk,x,y; -      while(m--){ inscanf"%d",&k); the         if(k==1){ thescanf"%d",&x); About             if(x>seg[1].maxlen) printf ("0\n"); the             Else{ theY=query (1, x); theprintf"%d\n", y); +Change1, y,y+x-1,0); -             } the         }Bayi         Else{ thescanf"%d%d",&x,&y); theChange1, x,x+y-1,1); -         } -     } the     return 0; the}

1593: [Usaco2008 Feb]hotel Hostel

Related Article

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.