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?
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 3993 |
2 | jiangly | 3743 |
3 | orzdevinwang | 3707 |
4 | Radewoosh | 3627 |
5 | jqdai0815 | 3620 |
6 | Benq | 3564 |
7 | Kevin114514 | 3443 |
8 | ksun48 | 3434 |
9 | Rewinding | 3397 |
10 | Um_nik | 3396 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 155 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
10 | nor | 152 |
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?
Название |
---|
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.