#P12054. Canteen Seating Simulation
Canteen Seating Simulation
Canteen Seating Simulation
There is a canteen in the first quadrant divided into $1\times 1$ regions. A region at $(x,y)$ is a square with vertices $(x,y)$, $(x,y+1)$, $(x+1,y)$, and $(x+1,y+1)$. Two regions $(x_1,y_1)$ and $(x_2,y_2)$ are adjacent if and only if $|x_1-x_2|+|y_1-y_2|=1$.
The canteen consists of two types of regions: corridors, where customers can move freely, and seats, where customers sit to dine. Every region $(x,y)$ satisfying $x\bmod 3\ne 0$ and $y\bmod 3\ne 0$ is a seat; all other regions are corridors. Four adjacent seats (forming a $2\times2$ block) compose a dining table.
Customers enter from $(0,0)$ (a corridor) and traverse along corridors only. When a customer steps into a seat, he immediately sits down. Each customer has a tolerance $o\in\{0,1,2\}$ that indicates his seating preference:
- For $o=0$, the customer will only sit on an empty seat if the entire corresponding table (all four seats of the $2\times2$ block) is empty.
- For $o=1$, the customer will only sit on an empty seat if all four adjacent seats (in the four cardinal directions, if they are seats) are empty.
- For $o=2$, the customer will sit on any empty seat.
Once a customer sits, he remains there regardless of future events.
There are $q$ events that occur sequentially. Each event is one of the following types:
- Type 1: A customer with tolerance $o$ enters from $(0,0)$ and searches for the seat that can be reached in the minimum number of moves via corridors, and that satisfies his seating preference. If several seats are tied, the one with the smallest $x$‐coordinate is chosen; if there is still a tie, the smallest $y$‐coordinate is chosen. Output the chosen seat coordinates.
- Type 2: The state of seat $(x,y)$ toggles. If the seat was occupied, the customer leaves immediately (output "leave"); if it was empty, a customer sits there immediately (output "sit").
Simulate the process and output the result for each event.
inputFormat
The first line contains a single integer $q$, the number of events.
Each of the next $q$ lines represents an event in one of two formats:
1 o
– A customer with tolerance $o$ (where $o\in\{0,1,2\}$) enters from $(0,0)$.2 x y
– The state of seat $(x,y)$ is toggled (guaranteed to be a seat).
outputFormat
For each event, output one line:
- For a type 1 event, output two integers separated by a space indicating the chosen seat's coordinates.
- For a type 2 event, output either
sit
orleave
depending on the change.
sample
5
1 2
2 1 1
1 0
2 1 1
1 1
1 1
leave
1 1
leave
1 1
</p>