I was trying to solve problem F from CERC 15. The problem was basically reduced to finding the sum . How can I find this sum in better than quadratic time without FFT?
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
I was trying to solve problem F from CERC 15. The problem was basically reduced to finding the sum . How can I find this sum in better than quadratic time without FFT?
Name |
---|
I didn't realize the FFT solution (which is pretty straightforward) while doing virtual so here's my (a bit messy) approach:
Think of the sum as a polynomial of a. More precisely, let then we are looking for
Now let's calculate Fy(a) according to Fy - 1(a):
Hence,
Since F0(a) is easy to calculate, we can achieve O(N * log(N)) time complexity, with logarithm factor being the cost for calculating modular inversions.
I have not read carefully your solution, but seeing just the last line I am pretty sure you got exactly the same solution as I got on contest. I first wrote FFT solution but at that time our FFT from library was not precise enough, so I needed to come up with completely different solution and did what you did. However there is a division by a - 1 in your formula. So you need to also consider case a = 1 :). But I have not done this on contest. And got AC either way :DD. However it is easy to fix, so that is not a big deal.
However there were other controversies about this problem. It has a really easy solution if (which can't be easily seen from presented here reduced version but can be seen from original statement). You can add to all values of F and you basically get rid of +c term and that makes problem very easy. But if you can't do this, you are basically screwed, there is no easy fix for this. But in tests there were no cases where P|a + b - 1, so many people wrote this solution and got it accepted.
Authors of that problem thought only about FFT solution that has no special cases and they missed other solutions (it turned out that there are at least two different approaches that were already described here), so they did not prepare tests against them what led to many participants getting not deserved AC.