D. Parking lottime limit per test
2 seconds
Memory limit per test
256 megabytes
Input
Standard Input
Output
Standard output
Nowadays it is becoming increasingly difficult to park a car in cities successfully. let's imagine a segment of a street as longLMeters along which
A parking lot is located. drivers shocould park their cars strictly parallel to the pavement on the right side of the street (remember that in the country the authors of the tasks come from the driving is right side !). Every driver when parking wants to leave
For themselves some extra space to move their car freely, That's why a driver is looking for a place where the distance between his car and the one behind his will be no lessBMeters
And the distance between his car and the one in front of his will be no lessFMeters (if there's no car behind then the car can be parked at the parking
Lot segment edge; the same is true for the case when there're no cars parked in front of the car ). let's introduce an axis of coordinates along the pavement. let the parking lot begin at point 0 and end at PointL.
The drivers drive in the direction of the coordinates 'creasing and look for the earliest place (with the smallest possible coordinate) where they can park the car. in case there's no such place, the driver drives on searching for his perfect Peaceful Haven.
Sometimes some cars leave the street and free some space for parking. considering that there never are two moving cars on a street at a time write a program that can use the data on the drivers, entering the street hoping to park there and the drivers leaving
It, to model the process and determine a parking lot space for each car.
Input
The first line contains three IntegersL,BBytesF(10 cores ≤ CoresLLimit ≤ limit 100000, limit 1 limit ≤ limitB, Bytes,FLimit ≤ limit 100 ).
The second line contains an integerN(1 digit ≤ DigitNLimit ≤0000100)
That indicates the number of requests the program has got. every request is described on a single line and is given by two numbers. the first number represents the request type. if the request type is equal to 1,
Then in that case the second number indicates the length of a car (in meters) that enters the street looking for a place to park. And if the request type is equal to 2,
Then the second number identifies the number of such a request (starting with 1) that the car whose arrival to the parking lot was described by a request with this
Number, leaves the parking lot. it is guaranteed that car was parked at the moment the request of the 2 type was made. The lengths of cars are integers from 1 to 1000.
Output
For every request of the 1 Type print number-1 on the single line
If the corresponding car couldn't find place to park along the street. otherwise, print a single number equal to the distance between the back of the car in its parked position and the beginning of the parking lot zone.
Sample test (s) Input
30 1 261 51 41 52 21 51 4
Output
06111723
Input
30 1 161 51 41 52 21 51 4
Output
0611176
Input
10 1 111 12
Output
-1
Title: http://www.codeforces.com/problemset/problem/46/D
It is to simulate the parking of a car, and then require space in front and rear of the car...
Analysis: similar to this question, the length of each car is changed to B + F + length, and the whole parking lot is also added with B and F, so there is no need to consider the space, just do it directly... The total length is actually 0 ~ L-1... I thought it was l... Infinite wa...
Code:
#include<cstdio>#include<iostream>#define ls rt<<1#define rs rt<<1|1#define lson l,m,ls#define rson m+1,r,rs#define uprt rt,m-l+1,r-musing namespace std;const int mm=111111;const int mn=mm<<2;int dly[mn],ml[mn],lm[mn],rm[mn];int sl[mm],sr[mm];void set(int rt,int op,int len){ ml[rt]=lm[rt]=rm[rt]=op?len:0; dly[rt]=op;}void pushdown(int rt,int l1,int l2){ if(dly[rt]<0)return; set(ls,dly[rt],l1); set(rs,dly[rt],l2); dly[rt]=-1;}void pushup(int rt,int l1,int l2){ ml[rt]=max(rm[ls]+lm[rs],max(ml[ls],ml[rs])); lm[rt]=lm[ls],rm[rt]=rm[rs]; if(lm[rt]>=l1)lm[rt]+=lm[rs]; if(rm[rt]>=l2)rm[rt]+=rm[ls];}void build(int l,int r,int rt){ ml[rt]=lm[rt]=rm[rt]=r-l+1; dly[rt]=-1; if(l==r)return; int m=(l+r)>>1; build(lson); build(rson);}void updata(int L,int R,int op,int l,int r,int rt){ if(L<=l&&R>=r) { set(rt,op,r-l+1); return; } int m=(l+r)>>1; pushdown(uprt); if(L<=m)updata(L,R,op,lson); if(R>m)updata(L,R,op,rson); pushup(uprt);}int query(int x,int l,int r,int rt){ if(lm[rt]>=x)return l; int m=(l+r)>>1,ret; pushdown(uprt); if(ml[ls]>=x)ret=query(x,lson); else if(rm[ls]+lm[rs]>=x)ret=m-rm[ls]+1; else ret=query(x,rson); pushup(uprt); return ret;}int main(){ int i,j,k,t,l,b,f,n; while(~scanf("%d%d%d",&l,&b,&f)) { scanf("%d",&n); l=b+l+f-1; build(0,l,1); for(t=1;t<=n;++t) { scanf("%d%d",&i,&j); if(i==1) { if(ml[1]>=b+j+f) { k=query(b+j+f,0,l,1); printf("%d\n",k); sl[t]=k+b; sr[t]=k+b+j-1; updata(sl[t],sr[t],0,0,l,1); } else puts("-1"); } else updata(sl[j],sr[j],1,0,l,1); } } return 0;}