CF46D.Parking Lot

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Nowadays it is becoming increasingly difficult to park a car in cities successfully. Let's imagine a segment of a street as long as L meters along which a parking lot is located. Drivers should 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 less than b meters and the distance between his car and the one in front of his will be no less than f meters (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 point L. The drivers drive in the direction of the coordinates' increasing 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.

如今,在城市中成功停车正变得越来越困难。我们设想一段长度为 LL 米的街道,其右侧(注意:本题作者所在国家靠右行驶!)设有一处停车场。驾驶员必须严格沿路缘石平行停放车辆,并且只能停在街道右侧。每位驾驶员在停车时,都希望为自己预留一定的额外空间以便自由移动车辆;因此,驾驶员会寻找一个位置,使得其车辆与后方车辆之间的距离不小于 bb 米,且与其前方车辆之间的距离不小于 ff 米(若后方无车,则可直接停靠在停车场起始端点处;同理,若前方无车,则可直接停靠在停车场末端点处)。我们沿路缘石建立一维坐标系,设停车场起点为坐标 00,终点为坐标 LL。驾驶员沿坐标轴正方向驶入街道,并寻找满足条件的、坐标值最小(即最靠前)的可停车位置。若不存在这样的位置,该驾驶员将继续前行,继续寻找其理想的宁静港湾。有时,部分车辆会驶离街道,从而腾出新的停车空间。假设任意时刻街道上至多只有一辆正在移动的车辆,请编写一个程序,根据驶入街道期望停车的驾驶员信息以及驶离街道的驾驶员信息,模拟整个过程,并为每辆车确定其停车位置。

输入格式

The first line contains three integers L, b и f (10 ≤ L ≤ 100000, 1 ≤ b, f ≤ 100). The second line contains an integer n (1 ≤ n ≤ 100) 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 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.

第一行包含三个整数 LL、bb 和 ff(10≤L≤10000010 \leq L \leq 100000,1≤b,f≤1001 \leq b, f \leq 100)。
第二行包含一个整数 nn(1≤n≤1001 \leq n \leq 100),表示程序接收到的请求总数。
每个请求占一行,由两个数字组成。第一个数字表示请求类型:

  • 若请求类型为 11,则第二个数字表示一辆驶入街道寻找停车位的汽车的长度(单位:米);
  • 若请求类型为 22,则第二个数字表示一个请求的编号(从 11 开始计数),该编号对应的请求曾描述过某辆汽车到达停车场,而当前请求表示这辆汽车离开停车场。
    保证在发出类型为 22 的请求时,所指汽车确实处于停放状态。
    汽车长度均为 11 至 10001000 之间的整数。

输出格式

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.

对于每个类型为 1 的请求,如果对应车辆无法在街道上找到停车位,则在单独一行输出数字 −1-1;否则,输出一个数字,表示该车停稳后其车尾到停车场区域起点的距离。

输入输出样例

  • 输入#1

    30 1 2
    6
    1 5
    1 4
    1 5
    2 2
    1 5
    1 4

    输出#1

    0
    6
    11
    17
    23
  • 输入#2

    30 1 1
    6
    1 5
    1 4
    1 5
    2 2
    1 5
    1 4

    输出#2

    0
    6
    11
    17
    6
  • 输入#3

    10 1 1
    1
    1 12

    输出#3

    -1

输入解题思路,AI测评打分。不知道怎么写?

首页