读书人

Codeforces#135(div.二) E.Parking lo

发布时间: 2013-11-22 23:06:19 作者: rapoo

Codeforces#135(div.2) E.Parking lot【线段树】

E. Parking Lottime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

A parking lot in the City consists of n parking spaces, standing in a line. The parking spaces are numbered from 1 to n from left to right.

When a car arrives at the lot, the operator determines an empty parking space for it. For the safety's sake the chosen place should be located as far from the already occupied places as possible. That is, the closest occupied parking space must be as far away as possible. If there are several such places, then the operator chooses the place with the minimum index from them. If all parking lot places are empty, then the car gets place number 1.

We consider the distance between the i-th and the j-th parking spaces equal to 4|i?-?j| meters.

You are given the parking lot records of arriving and departing cars in the chronological order. For each record of an arriving car print the number of the parking lot that was given to this car.

Input

The first line contains two space-separated integers n and m (1?≤?n,?m?≤?2105) — the number of parking places and the number of records correspondingly.

Next m lines contain the descriptions of the records, one per line. The i-th line contains numbers ti, idi (1?≤?ti?≤?2; 1?≤?idi?≤?106). If tiequals 1, then the corresponding record says that the car number idi arrived at the parking lot. If ti equals 2, then the corresponding record says that the car number idi departed from the parking lot.

Records about arriving to the parking lot and departing from the parking lot are given chronologically. All events occurred consecutively, no two events occurred simultaneously.

It is guaranteed that all entries are correct:

读书人网 >编程

热点推荐