POLYEVAL - Editorial

Here’s my solution, no FFT required.

eval(P,x[]): # returns map x : P(x)
    if P = constant: return map [a : constant for a in x]
    P(a) = P1(a**2)+a*P2(a**2)
    x2 = set [(a**2)% for a in x]
    y1 = eval(P1,x2)
    y2 = eval(P2,x2)
    return map [a : (y1[a**2]+a*y2[a**2])% for a in x]

Tada!

It turns out that the number of different values of x^{2^k}\ \% is approx. mod/2^k, and since the degrees of polynomials P_1,P_2 are halved everytime you go deeper in the recursion, the time complexity is O(mod\log^2{mod}).

That second logarithm is annoying, but we can improve it by using the fact that the set x2 depends only on recursion depth and not on the polynomials, and then the small value of mod to replace map access (by value) with array access (by index). It’s sufficient to use two arrays for each recursion depth, then, which gives us O(mod\log{mod}) in both time and memory.

BTW, difficulty Simple? ( ͡° ͜ʖ ͡°)

4 Likes

You call this simple? I think there must be a number to the relative hardness of the problem, based on number of attempts, the rating of coders who attempted it, those who got it right, those who couldn’t, etc. ‘Simple’ is like too much! :stuck_out_tongue:

5 Likes

Just asking, was anybody able to solve this using general multipoint evaluation ??
Or is it even practically feasible for this problem ?

1 Like

Can anybody explain this part of the problem setter’s solution:

pw[0] = 1;
for(int i = 1; i < (1 << 18); i++)
    pw[i] = (pw[i - 1] * root) % mod;
for(int i = 0; i < (1 << 18); i++) {
    ans[pw[i]] = a[i];
    ans[pw[i] * 10 % mod] = b[i];
    ans[pw[i] * 100 % mod] = c[i];
}
1 Like

@dpraveen :diamonds::diamonds: In line 116 in your code, you have done REP(add, 3), when add is the name of the function you have used to add modulo mod. It’s creating a confusion, please replace it with another variable name.

Heading #### Can anyone explain step-by-step the functioning of fft function in setter’s soln ??

And also the importance of 786433 ??

Explanation with an example would be helpfull

I am new at this

Why is it needed to decompose in 3 polynomials ?? Can we concat 2^18 zeroes so that final polynomial becomes of 2^20 numbers which is perfect square and do NTT?? @n1t1n_153012

Hi Xellos0, "It turns out that the number of different values of x^{2^k} % is approx mod/2^k", this fact you can prove directly using FFT. Instead if you see the pseudo code that I have shown in the editorial, it directly maps to yours except the generator part, which can be omitted too if one wants :slight_smile:

Oh, yeah, it is. I just didn’t think of FFT at all, expecting it to have a “simpler” solution, wrote a a bruteforce and modified it until it passed.

1 Like

Poor editorial. Can u please explain with a good example. Suppose the modulo was 10^9+7(in most cases) and the problem is same with constraints on a(i) and x(i) being <= 10^9 , how to solve this?
Btw I am new to this and have less idea of FFT.

Wait till 16th and you will get what you are looking for :slight_smile:

1 Like

I didn’t understand the reason for 16th??

1 Like

Then read what FFT is instead of complainin’ an editorial is poor just because you can’t comprehend it, see?
If the problem itself have more specific constraints, why would the editorialist have to explain beyond it? Ain’t their responsibility.

So your motive is just to get AC somehow and problem is finished…Nice…

Ain’t my motive. But that’s the editorialist’s motive, to write the editorial detailed specifically for this 1 problem and move on.

1 Like

i think u wanna for Binomial Fever … :stuck_out_tongue_winking_eye:

Naaa… I have the complete solution for it… it isn’t using this concept…but it was very nice…only need to optimize the constants in Big O notation

1 Like

So you discussed all the details about FFT rather discussing the details about your problem? Man!

Bruh this editorial is used to learn multipoint evaluation. It was written in the time when even blogs on fft were rare.

1 Like

Yeah. I see now. I didn’t notice the date.
I am really sorry though. :frowning:

Another thing, I am really having trouble to visualize the solution here. Can you please explain why do we take 3 polynomial here and what is it going on when we are combining three polynomials into the answer?

Thanks a lot.