P5554 Basketball Statistics
Background
Xiao L likes singing, dancing, rap, and basketball.
At the same moment, there may be many basketballs in the air on the court, and Xiao L wants to collect statistics about these basketballs.
Description
When a basketball is thrown into the air, Xiao L records a time $l$, from which this basketball starts being counted by Xiao L. When a basketball is caught, Xiao L records a time $r$, after which the state of this basketball is no longer counted by Xiao L. For each basketball, Xiao L computes the height of this basketball at time $l$ and its initial upward velocity.
For a time $x$, Xiao L wants to know: among all basketballs that are still in the air at that moment, what is the height of the highest one.
**Note**: The discovered basketballs' times $l, r$ and Xiao L's query times $x$ have no monotonicity.
Input Format
The first line contains an integer $m$.
The next $m$ lines each describe an operation or a query, in one of the following forms:
1. `add a v l r`: Xiao L discovers a basketball in the air. This basketball is thrown into the air at time $l$ and is caught at time $r$. Its height at time $l$ is $a$, and its initial upward velocity is $v$.
2. `query x`: Please tell Xiao L, based on the information he has given so far, what the maximum height is among all basketballs that are in the air at time $x$.
Output Format
For each `query` operation, output one line containing this maximum height. If there is no basketball in the air at that time, output `Undefined`.
To reduce precision errors, it is recommended to use the `long double` type to store floating-point numbers, and use `%Lf` as the output format.
To avoid precision issues, this problem uses **Special Judge**. If the difference between your answer and the reference solution's answer is less than or equal to $0.005$, it will be considered correct.
Explanation/Hint
For $30\%$ of the testdata, $m \le 5000$.
For another $30\%$ of the testdata, $-100 < l, r, x < 100$.
For $100\%$ of the testdata, $1 \le m \le 100000$, $-1000 < a, v < 1000$, $-10^6 < l, r, x < 10^6$, $l \le r$. It is guaranteed that all decimals in the input have exactly $3$ digits after the decimal point.
The basketball's height may be negative.
### Xiao K Teaches You Physics
All units in this problem use the International System of Units (SI). That is, the time unit is seconds ($s$), and the length unit is meters ($m$).
In this problem, the gravitational acceleration is $g = 9.8 ~ m \cdot s^{-2}$.
Ignoring the horizontal displacement of the basketball, we can treat its motion as **vertical upward throw motion**. Based on the information given in the statement, if the basketball's initial height is $a$, initial velocity is $v$, gravitational acceleration is $g$, and the **time in the air** is $t$, then the height of the basketball at that time is $-\dfrac 1 2 g t^2 + vt + a$.
Translated by ChatGPT 5