#C3578. Plant Growth Rate Query
Plant Growth Rate Query
Plant Growth Rate Query
You are given a sequence of operations to record the height of a plant on specific days and to query its average growth rate over a period. There are two types of operations:
record d h
: Record that the plant's height is h on day d.query d1 d2
: Query the average growth rate between day d1 and day d2.
For a query, if the heights on both days are recorded, the average growth rate is computed as
$$\text{growth rate} = \frac{H(d_2)-H(d_1)}{d_2-d_1},$$
and the result is to be printed with exactly 4 decimal places. If either day does not have a recorded height, the output is 0.0000
.
All input is read from standard input (stdin) and all output should be written to standard output (stdout).
inputFormat
The first line of input contains an integer n — the number of operations. The following n lines each contain an operation in one of the following two formats:
record d h
— record that on day d the plant's height is h.query d1 d2
— query the average growth rate between day d1 and day d2.
outputFormat
For every query operation, output a line containing the computed growth rate formatted to exactly 4 decimal places. If one or both of the specified days have no recorded height, output 0.0000
for that query.
6
record 1 3
record 2 8
record 3 10
record 4 15
record 5 18
query 2 5
3.3333