題意 "題目鏈接" Sol 直接把$q_i$除掉 那麼$E_j = \sum_{i = 1}^{j 1} q_i (i j)^2 \sum_{i = j + 1}^n q_i (i j)^2$ 設$f_i = q_i, g_i = i^2$ 帶入原式發現原式變成了捲積的形式 $E_j = f_i g ...
題意
Sol
直接把\(q_i\)除掉
那麼\(E_j = \sum_{i = 1}^{j - 1} q_i \frac{1}{(i - j)^2} - \sum_{i = j + 1}^n q_i \frac{1}{(i - j)^2}\)
設\(f_i = q_i, g_i = \frac{1}{i^2}\)
帶入原式發現原式變成了捲積的形式
\(E_j = f_i g_{i - j}\)
然後像\(BZOJ2194\)那樣把\(g\)給翻轉掉,就成了標準捲積形式
FFT一波
// luogu-judger-enable-o2
#include<bits/stdc++.h>
const double Pi = acos(-1);
using namespace std;
const int MAXN = 1e6 + 10;
int N, M, r[MAXN];
struct com {
double x, y;
com(double xx = 0, double yy = 0) {x = xx; y = yy;}
com operator + (com &rhs) {
return com(x + rhs.x, y + rhs.y);
}
com operator - (com &rhs) {
return com(x - rhs.x, y - rhs.y);
}
com operator * (com &rhs) {
return com(x * rhs.x - y * rhs.y, x * rhs.y + y * rhs.x);
}
}a[MAXN], b[MAXN], c[MAXN];
void FFT(com *a, int N, int type) {
for(int i = 0; i < N; i++) if(i < r[i]) swap(a[i], a[r[i]]);
for(int mid = 1; mid < N; mid <<= 1) {
com Wn(cos(Pi / mid), type * sin(Pi / mid));
for(int R = mid << 1, j = 0; j < N; j += R) {//這裡要寫<N
com w(1, 0);
for(int k = 0; k < mid; k++, w = w * Wn) {
com x = a[j + k], y = w * a[j + k + mid];
a[j + k] = x + y;
a[j + k + mid] = x - y;
}
}
}
if(type == -1) {
for(int i = 0; i <= N; i++) a[i].x /= N;
}
}
int Mul(com *c, com *a, com *b, int N, int M) {
int ret = 1, l = 0;
while(ret <= N + M) ret <<= 1, l++;
for(int i = 0; i < ret; i++) r[i] = (r[i >> 1] >> 1) | ((i & 1) << l - 1);
FFT(a, ret, 1);
FFT(b, ret, 1);
for(int i = 0; i <= ret; i++) c[i] = a[i] * b[i];
FFT(c, ret, -1);
return ret;
}
int main() {
scanf("%d", &N); N -= 1;
for(int i = 0; i <= N; i++) scanf("%lf", &a[i].x);
for(int i = 0; i < N; i++) b[i].x = -1.0 / (double)(N - i) / (double)(N - i);
for(int i = N + 1; i <= 2 * N; i++) b[i].x = -b[2 * N - i].x;
Mul(c, a, b, N, 2 * N);
for(int i = N; i <= N * 2; i++) printf("%.5lf\n", c[i].x);
return 0;
}