Разбор
Problem Author: | Maksym Shvedchenko, Illia Shevchenko |
Prepared by: | Maksym Shvedchenko, Illia Shevchenko, Illia Fursov |
Editorial by: | Maksym Shvedchenko |
Group 1: ; ;
Let's notice that our equation:
Can be rewritten as:
In other words, it is an identity, so all satisfy it, therefore it is enough to output the word "Infinity
".
Group 2:
In this group, there are two key cases:
When , it is again an identity and the answer is Infinity.
Otherwise, we can use the fact that shows the distance between points on the number line and the equation simply shows that the distance from point to and from to are equal. Such a point is exactly one and it lies exactly in the middle between and , indeed, because the midpoint of points lying at equal distances from the given points is the perpendicular bisector of the segment connecting the given points, and since we are solving the problem in real numbers, only one point, which we described above, will suit us.
For all subsequent test groups, we will need a few observations:
if and otherwise. In the future, we will call the first situation as "the absolute value opens with a positive sign", and "the second as the absolute value opens with a negative sign".
Let's move everything from right to left, now our task is to find the number of zeros in such a function:
In one interval where no absolute value will change its sign, our function will be a straight line. This happens because our expression turns into an expression without absolute values, then we can group and everything else and get the formula - a straight line.
Breakpoints, when the sign of some absolute value (and consequently the function) changes, coincide with an element from the array or from the array .
The maximum number of breakpoints is .
From the previous fact, it follows that the maximum number of different pieces of straight lines (from which our function consists) is .
Group 3: ; ;
Let's just consider the half-intervals In each of them, the value of the function is the same because the breakpoint could only be an integer. In each case, we can expand the absolute values, compose a linear function , find such an that , and check if lies in the given half-interval. Here are 3 remarks worth making:
if then "
Infinity
" can be output.if then we can simply move on
in general, this can also be considered in fractional numbers, but it can be noticed that our will always be rational numbers, which means they can be represented as a fraction and compared as a fraction (there will be no problems with accuracy)
Group 4:
It can be easily noticed that when considering an interval of length 1, many functions will have the same formula. Instead, let's consider the half-intervals between two neighboring breakpoints. For this, we will create an array containing all elements of the array and the array , sort it and consider such half-intervals:
And on each of them, we will solve it just like in the previous group, the solution for one segment will work in , so the total asymptotic will be
Group 5:
For this group, let's optimize the algorithm for creating a function for one interval. Let's notice that where
The algorithm for constructing will be further discussed, notice that for everything is analogous.
The first step is to sort the array .
Let's say we have the half-interval then the number of absolute values that opened with a positive sign is the number of such numbers that and with a negative sign, it is all the rest, then the coefficient in our function is the difference between the first and second number. With the remaining coefficient, everything is slightly more complicated, let's call such a maximum number that Then, rewriting our expression without the absolute value, we get:
So our task has been reduced to the task of finding the sum on the segment, which can be done using prefix sums.
On one half-interval, we can handle it in , so the total asymptotic will be