#P9270. [CEOI 2013] 有轨电车 / Tram
[CEOI 2013] 有轨电车 / Tram
Background
Translated from CEOI 2013 Day 1。
The seats in the trams operating in Zagreb form a grid with rows and columns. The distance between two seats is the Euclidean distance (straight-line distance) between the centers of the corresponding grid squares.
Most passengers are socially anxious when using public transport. That is, when a passenger enters the tram, they choose an empty seat such that the distance to the nearest occupied seat is as large as possible. If there are multiple such seats, they always choose a seat with a smaller row number (because then they do not need to walk too far). If there are still multiple such seats, they choose the seat with the smaller column number (i.e., column ). After choosing a seat, the passenger stays there until they leave the tram. If the tram is empty, an entering passenger will always choose the seat in row , column .
Problem Description
You are given a sequence of events. Each event is either a passenger entering the tram or a passenger leaving the tram. You need to output where the passenger will sit when they enter. The tram is initially empty.
There are events in the input, numbered from to in the order they occur. There are two types of events: an E event means a passenger enters the tram, and an L event means a passenger leaves the tram. For an L event, an integer is also given, meaning that the passenger leaving in this event is the passenger who entered in event .
The testdata guarantees that whenever a passenger tries to enter the tram, there is at least one empty seat in the tram.
Input Format
The first line contains two integers and .
The next lines describe the events. Line describes event : first a character E or L is given, and if the character is L, then a number is given. It is guaranteed that event is of type E.
Output Format
The number of lines in the output should be equal to the number of E events in the input. For the -th E event, output on line the seat number (row and column) chosen by that passenger, separated by a space.
3 7
E
E
E
L 2
E
L 1
E
1 1
3 2
1 2
3 1
1 1
13 9
E
E
E
E
E
E
E
E
E
1 1
13 2
7 1
4 2
10 1
2 2
3 1
5 1
6 2
10 9
E
E
E
E
L 3
E
E
L 6
E
1 1
10 2
5 2
7 1
4 2
2 2
4 1
Hint
For of the data, .
For of the data, .
For of the data, .
For of the data, .
The first three test points are samples.
Translated by ChatGPT 5