题意:$$F(i)= sum_{j=0} ^{i - 1} frac{qi * qj}{(j - i)^{2}} - sum_{j = i + 1}^{n} frac{qi * qj}{(j - i)^{2}}$$
求Fi/qi
题解:可以分开来算 前面一坨 后面一坨
[f(i) = qi
]
[g(i)=frac{1}{i^2}
]
[F(i) = sum_{j = 0}^{i - 1} f(i) * g(i - j) - sum_{j = i + 1}^{n} f(i) * g(j - i)
]
前面已经可以算了 然后后面的g(j - i) = g(i - j) 套路的把f翻转一下
[sum_{j = i + 1}^{n} f(n - j + 1) * g(j - i) = F(n + 1 - i)
]
[然后就都可以卷了!
]
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
struct Complex {
double x, y;
Complex(double _x = 0.0, double _y = 0.0) {
x = _x;
y = _y;
}
Complex operator + (const Complex &b) const {
return Complex(x + b.x, y + b.y);
}
Complex operator - (const Complex &b) const {
return Complex(x - b.x, y - b.y);
}
Complex operator * (const Complex &b) const {
return Complex(x * b.x - y * b.y, x * b.y + y * b.x);
}
};
void change(Complex y[], int len) {
int i, j, k;
for(i = 1, j = len / 2; i < len - 1; i++) {
if(i < j) swap(y[i], y[j]);
k = len / 2;
while(j >= k) {
j -= k;
k /= 2;
}
if(j < k) j += k;
}
}
void fft(Complex y[], int len, int on) {
change(y, len);
for(int h = 2; h <= len; h <<= 1) {
Complex wn(cos(-on * 2 * PI / h), sin(-on * 2 * PI / h));
for(int j = 0; j < len; j += h) {
Complex w(1, 0);
for(int k = j; k < j + h / 2; k++) {
Complex u = y[k];
Complex t = w * y[k + h / 2];
y[k] = u + t;
y[k + h / 2] = u - t;
w = w * wn;
}
}
}
if(on == -1)
for(int i = 0; i < len; i++)
y[i].x /= len;
}
Complex x1[400005], x2[400005], x3[400005];
int main() {
int n;
scanf("%d", &n);
for(int i = 1; i <= n; i++) {
double x;
scanf("%lf", &x);
x1[i] = Complex(x, 0);
x2[n - i + 1] = Complex(x, 0);
x3[i] = Complex(1.0 / (1.0 * i * i), 0);
}
int len = 1;
while(len <= n + n) len <<= 1;
fft(x1, len, 1);
fft(x2, len, 1);
fft(x3, len, 1);
for(int i = 0; i <= len; i++) x1[i] = x1[i] * x3[i];
for(int i = 0; i <= len; i++) x2[i] = x2[i] * x3[i];
fft(x1, len, -1);
fft(x2, len, -1);
for(int i = 1; i <= n; i++) {
printf("%.3lf
", x1[i].x - x2[n - i + 1].x);
}
return 0;
}