#P5139. Quadratic Function Operations and Queries
Quadratic Function Operations and Queries
Quadratic Function Operations and Queries
You are given a quadratic function in the form $$y=ax^2+bx+c,$$ where \(a\neq 0\). Initially, you may be asked to compute its extreme value (minimum if \(a>0\) or maximum if \(a<0\)). However, the difficulty is increased by a series of operations that modify the function or query its properties.
The following operations can be applied sequentially:
- Vertical Shift: Given a coefficient \(k\), shift the function vertically. That is, update the function as $$y = ax^2 + bx + (c+k).$$
- Horizontal Shift: Given a coefficient \(k\), shift the function horizontally. The new function becomes $$y = a(x-k)^2 + b(x-k) + c.$$ After expanding, the coefficients update to: $$a'=a,\quad b' = b-2ak,\quad c' = ak^2 - bk + c.$$
- Reflection about a Point: Given coefficients \(k_1\) and \(k_2\), reflect the function about the point \((k_1,k_2)\). The new function is given by $$y = 2k_2 - f(2k_1 - x).$$ For \(f(x)=ax^2+bx+c\), after expanding, the updated coefficients are: $$a'=-a,\quad b'=4ak_1+b,\quad c'=2k_2-(4ak_1^2+2bk_1+c).$$
- Interval Extreme Query: Given two numbers \(k_1\) and \(k_2\) (with \(k_1\le k_2\)), compute the minimum and maximum values of the current quadratic function on the closed interval \([k_1,k_2]\). Recall that for a quadratic function \(f(x)=ax^2+bx+c\), the vertex is at \(x=-\frac{b}{2a}\). Evaluate \(f(k_1)\), \(f(k_2)\), and \(f(-\frac{b}{2a})\) (if the vertex lies in \([k_1,k_2]\)) to determine the extreme values.
- Intersection Query: Given coefficients \(u,v,w\) defining another quadratic function
$$y_2=ux^2+vx+w,$$
determine whether the current quadratic function \(y=ax^2+bx+c\) and \(y_2\) have any intersection points.
Hint: They intersect if the equation $$(a-u)x^2+(b-v)x+(c-w)=0$$ has at least one real solution. Be careful with the case when \(a-u=0\).
After processing all operations, output the extreme value of the final quadratic function. Specifically, output the minimum value if \(a>0\) or the maximum value if \(a<0\) (which is achieved at the vertex \(x=-\frac{b}{2a}\)).
Input Format:
- The first line contains three integers \(a\), \(b\), and \(c\) representing the initial quadratic function \(y=ax^2+bx+c\).
- The second line contains an integer \(Q\) indicating the number of operations.
- The following \(Q\) lines each describe an operation. Each operation starts with an integer indicating its type:
- Type 1:
1 k
- Type 2:
2 k
- Type 3:
3 k1 k2
- Type 4:
4 k1 k2
— perform a query on the interval \([k1,k2]\) and output the minimum and maximum values (separated by a space). - Type 5:
5 u v w
— perform a query to check whether the current function and the quadratic function \(y_2=ux^2+vx+w\) have an intersection. OutputYES
if they intersect, andNO
otherwise.
- Type 1:
Output Format:
- For each operation of type 4, output a line containing two numbers: the minimum and maximum values of the quadratic function on the given interval.
- For each operation of type 5, output a line containing either
YES
orNO
depending on whether an intersection exists. - After processing all operations, output a final line containing the extreme value (minimum if \(a>0\) or maximum if \(a<0\)) of the final quadratic function.
It is guaranteed that the input values are such that all operations can be performed without ambiguity.
inputFormat
The input begins with a line containing three integers \(a\), \(b\), and \(c\) (with \(a\neq0\)), representing the quadratic function \(y=ax^2+bx+c\). The next line contains an integer \(Q\) representing the number of operations. The following \(Q\) lines each describe an operation in one of the following formats:
1 k
2 k
3 k1 k2
4 k1 k2
5 u v w
For operation type 4, it is guaranteed that \(k1 \le k2\).
outputFormat
For each operation of type 4 or 5, output a line with the corresponding result. For type 4, print the minimum value followed by a space and the maximum value on the specified interval. For type 5, print YES
if the current quadratic function intersects with the given quadratic function, otherwise print NO
. Finally, after all operations have been processed, output one line containing the extreme value (minimum if \(a>0\) or maximum if \(a<0\)) of the final quadratic function.
sample
1 -2 1
3
1 3
4 0 2
5 1 -2 1
3 4
NO
3
</p>