Ants in a Corridor
Time limit3sMemory limit512 MB
Ants join a corridor over time and bounce off each other and both walls, and each query asks for the position of one numbered ant.
Problem
A corridor is a segment of length . The corridor carries coordinates: its left endpoint is , its right endpoint is , and the point that divides the corridor internally in the ratio has coordinate .
Whenever Gyeonggeun is bored, he puts one more ant on the corridor. Every ant on this corridor moves either left or right and covers distance per second. The corridor is only wide enough for one ant. When two ants moving in opposite directions meet at a point, both reverse direction at once and keep the same speed. An ant that reaches an endpoint of the corridor also reverses direction at once and keeps the same speed. Treat an ant as a point with no size. Two ants collide only when their coordinates are exactly equal, and an ant turns around only when its coordinate is exactly or exactly .
At time seconds the corridor holds no ants. Write a program that processes operations of the following two kinds.
- At second , put an ant moving right or left at coordinate . If this ant is the -th one placed, it gets number .
- Print the coordinate of ant number at second .
Input
The first line contains two positive integers and (, ).
Each of the next lines holds one operation. Every line starts with an integer (), the second at which the operation happens, and a positive integer (), the kind of the operation. The rest of the line is as follows.
- If , an integer () and an integer () follow. At second an ant is placed at coordinate , moving right when and left when . The input never places an ant on a coordinate that another ant occupies at that second.
- If , the number of the ant follows. It is at least and at most the number of ants placed so far. Print the coordinate of ant number at second .
The operations come in increasing order of , and no two operations share the same .
Output
For each operation with , print the coordinate of that ant on its own line. Under these constraints the coordinate at a query time is always an integer, so print it as an integer.