题目链接
已知
F
j
=
∑
i
<
j
q
i
q
j
(
i
−
j
)
2
−
∑
i
>
j
q
i
q
j
(
i
−
j
)
2
F_{j}=\sum_{i<j}\frac{q_iq_j}{(i-j)^2}-\sum_{i>j}\frac{q_iq_j}{(i-j)^2}
Fj=i<j∑(i−j)2qiqj−i>j∑(i−j)2qiqj
令
E
i
=
F
i
q
i
E_i=\frac{F_i}{q_i}
Ei=qiFi求
E
i
E_i
Ei
显然
E
j
=
∑
i
<
j
q
i
(
i
−
j
)
2
−
∑
i
>
j
q
i
(
i
−
j
)
2
E_{j}=\sum_{i<j}\frac{q_i}{(i-j)^2}-\sum_{i>j}\frac{q_i}{(i-j)^2}
Ej=i<j∑(i−j)2qi−i>j∑(i−j)2qi
令
f
(
x
)
=
∑
i
=
0
n
−
1
a
i
+
1
x
i
,
g
(
x
)
=
∑
i
=
n
2
n
−
2
x
i
(
i
−
n
+
1
)
2
−
∑
i
=
0
n
−
2
x
i
(
n
−
i
−
1
)
2
,
h
(
x
)
=
f
(
x
)
∗
g
(
x
)
f(x)=\sum_{i=0}^{n-1}{a_{i+1}x^{i}},g(x)=\sum_{i=n}^{2n-2}\frac{x^i}{(i-n+1)^2}-\sum_{i=0}^ {n-2}\frac{x^i}{(n-i-1)^2},h(x)=f(x)* g(x)
f(x)=i=0∑n−1ai+1xi,g(x)=i=n∑2n−2(i−n+1)2xi−i=0∑n−2(n−i−1)2xi,h(x)=f(x)∗g(x)
取
h
(
x
)
n
−
1
h(x)n-1
h(x)n−1~
2
(
n
−
1
)
2(n-1)
2(n−1)次系数即为答案 。
#include <cmath>
#include <cstdio>
#include <complex>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long double ld;
typedef complex<ld> cp;
const int N = 1 << 19;
const ld pi = acos((ld)-1.0);
int n, m, bit, rev[N];
bool flag;
cp A[N], B[N];
inline void FFT(cp *y) {
for (int i = 0; i < n; i++) if (i < rev[i]) swap(y[i], y[rev[i]]);
for (int i = 1; i <= bit; i++) {
int fac = 1 << i;
cp omega_n(cos(2 * pi / fac), sin(2 * pi / fac));
if (flag) omega_n.imag() *= -1;
for (int j = 0; j < n; j += fac) {
cp omega(1, 0);
for (int k = 0; k < fac>>1; k++, omega *= omega_n) {
cp u = y[j + k], t = omega*y[j + k + (fac>>1)];
y[j + k] = u + t, y[j + k + (fac>>1)] = u - t;
}
}
}
}
int main() {
scanf("%d", &m);
for (int i = 0; i < m; i++) scanf("%Lf", &A[i].real());
for (int i = 0; i < m - 1; i++)
B[i].real() = - 1 / ((ld)(m - i - 1)*(m - i - 1));
for (int i = m; i < 2 * m - 1; i++)
B[i].real() = 1 / ((ld)(i - m + 1)*(i - m + 1));
for (n = 1; n < 4*m - 2; n <<= 1) bit++;
for (int i = 0; i < n; i++) rev[i] = (rev[i>>1] >> 1) | ((i & 1) << (bit - 1));
FFT(A); FFT(B); for (int i = 0; i < n; i++) A[i] *= B[i];
flag = true; FFT(A);
for (int i = m - 1; i < 2 * m - 1; i++)
printf("%Lf\n", A[i].real() / n);
return 0;
}