eolymp
bolt
Try our new interface for solving problems
Məsələlər

Dining Room

Dining Room

One famous company has employees of two types: extroverts and introverts. These two kinds of people differ in many ways, and in this problem we consider the difference in their behavior during the dinner. The dining room in this company can be represented as a rectangular grid \textbf{N}×\textbf{M}. In other words, each point with integer coordinates \textbf{x}, \textbf{y} (\textbf{0} ≤ \textbf{x} ≤ \textbf{N}, \textbf{0} ≤ \textbf{y} ≤ \textbf{M}) contains a table. Each table is for one person. \includegraphics{https://static.e-olymp.com/content/5f/5f71f5277f8b4c05b482f4ec2dc93d321273d622.jpg} We say that the (Euclidean) distance between points with coordinates (\textbf{x_1}, \textbf{y_1}) and (\textbf{x_2}, \textbf{y_2}) is equal to . When an introvert comes to the dining room, he selects such a free table that the minimal distance from it to the nearest occupied table is as large as possible. If there are several tables with the largest minimal distance, he selects the one of them with the smallest \textbf{x} coordinate. If there are still several tables, he selects the one of them with the minimal \textbf{y} coordinate. When an extrovert comes to the dining room, he selects such a free table that the maximal distance from it to the farthest occupied table is as small as possible. If there are several tables with the smallest maximal distance, he selects the one of them with the smallest \textbf{x} coordinate. If there are still several tables, he selects the one of them with the minimal \textbf{y} coordinate. You are given the size of the dining room and the description of \textbf{Q} events. Each event is either an arrival or a departure of one person. For each arrival you have to find the table that he occupies. \InputFile The first line on the input contains integers \textbf{N}, \textbf{M}, \textbf{Q} separated by spaces (\textbf{1} ≤ \textbf{N}, \textbf{M} ≤ \textbf{5000}, \textbf{0} ≤ \textbf{Q} ≤ \textbf{100}). Next \textbf{Q} lines describe events. If the \textbf{i}'th event is an arrival of an extrovert, the \textbf{i}'th line contains single string "\textbf{ext}"; if the event is an arrival of an introvert, the line contains single string "\textbf{int}"; if the event is a departure of some person, the line contains the \textbf{1}-based index (among all events) of the event that describes his arrival. It is guaranteed that the input data is correct, i.e. for each arriving human there is at least one empty table in the dining room at the moment of his arrival, and for each event of the departure the index described in the line corresponds to an event of arrival and the person arrived in this event is still inside the dining room. \OutputFile For each arrival print a line containing two space-separated integers - the coordinates of the table being occupied.
Zaman məhdudiyyəti 3 saniyə
Yaddaşı istafadə məhdudiyyəti 256 MiB
Giriş verilənləri #1
5 5 5
int
1
ext
3
int
Çıxış verilənləri #1
0 0
0 0
0 0