持续更新(last upd 2019.4.28)
ZJOI2014 力
解法
对原式进行转换,然后卷积FFT
套上去求解就可以了。
推导过程简洁版:
\[F_i=\sum_{j<i} \frac{q_iq_j}{(i-j)^2}-\sum_{j>i} \frac{q_iq_j}{(i-j)^2}\]
\[E_i=\sum_{j=1}^{i-1}\frac{q_j}{(i-j)^2}-\sum_{j=i+1}^{n}\frac{q_j}{(j-i)^2}\]
\[E_i=\sum^{i-1}_{j=1}q_jf_{i-j}-\sum^n_{j=i+1}q_jf_{j-i}\]
对以上的式子前后分别做FFT
就可以了
主程序(大致框架)
int main() {
read(n);
for (int i = 1; i <= n; i ++) {
db x; scanf("%lf", &x);
a[i].x = c[n - i + 1].x = x; b[i].x = d[i].x = 1.0 / sqr(i * 1.0);
}
limit = 1; while (limit <= (n << 1)) limit <<= 1, l ++;
for (int i = 0; i < limit; i ++) r[i] = (r[i >> 1] >> 1) | ((i & 1) << (l - 1));
FFT(a, 1); FFT(b, 1);
for (int i = 0; i < limit; i ++) a[i] = a[i] * b[i];
FFT(a, -1);
FFT(c, 1); FFT(d, 1);
for (int i = 0; i < limit; i ++) c[i] = c[i] * d[i];
FFT(c, -1);
for (int i = 1; i <= n; i ++) printf("%.3lf\n", a[i].x - c[n - i + 1].x);
return 0;
}