# Problem

## Description

$F_j=\sum_{i<j} \frac{q_iq_j}{(i-j)^2} - \sum_{i>j} \frac{q_iq_j}{(i-j)^2}$

$$E_i=F_i/q_i$$，求 $$E_i$$

## Output Format

$$n$$ 行，第 $$i$$ 行输出 $$E_i$$。与标准答案误差不超过 $$10^{-2}$$ 即可。

## Sample

### Input

5
4006373.885184
15375036.435759
1717456.469144
8514941.004912
1410681.345880


### Output

-16838672.693
3439.793
7509018.566
4595686.886
10903040.872


# Mentality

$E_i=\sum_{j=1}^{i-1}\frac{q_j}{(i-j)^2}-\sum_{j=i+1}^n\frac{q_j}{(j-i)^2}$

$$g_i=\frac{1}{i^2}$$ ，则有：

$E_i=\sum_{j=1}^{i-1}q_jg_{i-j}-\sum_{j=i+1}^nq_jg_{j-i}$

$\sum_{j=1}^{i-1}q_jg_{i-j}=\sum_{j=0}^{i}q_jg_{i-j}$

$\sum_{j=i+1}^nq_jg_{j-i}=\sum_{j=0}^{n-i+1}p_jg_{n-i+1-j}$

# Code

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
#define cp complex<double>
const int Max_n = 3e5 + 5;
const double pi = acos(-1);
int n;
int rev[Max_n];
double dv[Max_n], ans[Max_n], q[Max_n];
cp f[Max_n], g[Max_n];
namespace FFT {
int lim, bit;
void dft(cp *f, int t) {
for (int i = 0; i < lim; i++)
if (rev[i] > i) swap(f[rev[i]], f[i]);
for (int len = 1; len < lim; len <<= 1) {
cp Wn = exp(cp(0, t * pi / len));
for (int i = 0; i < lim; i += len << 1) {
cp Wnk(1, 0);
for (int k = i; k < i + len; k++, Wnk *= Wn) {
cp x = f[k], y = Wnk * f[k + len];
f[k] = x + y, f[k + len] = x - y;
}
}
}
}
void fft(double *a, double *b, int tot) {
lim = 1, bit = 0;
while (lim <= tot) lim <<= 1, bit++;
for (int i = 0; i < lim; i++)
rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (bit - 1));
for (int i = 0; i < lim; i++) f[i] = a[i], g[i] = b[i];
dft(f, 1), dft(g, 1);
for (int i = 0; i < lim; i++) f[i] *= g[i];
dft(f, -1);
for (int i = 0; i < lim; i++) f[i] /= lim;
}
}  // namespace FFT
using namespace FFT;
int main() {
#ifndef ONLINE_JUDGE
freopen("3338.in", "r", stdin);
freopen("3338.out", "w", stdout);
#endif
cin >> n;
for (int i = 1; i <= n; i++) scanf("%lf", &q[i]);
for (int i = 1; i <= n; i++) dv[i] = (double)(1.0 / i / i);
fft(q, dv, n << 1);
for (int i = 1; i <= n; i++) ans[i] += f[i].real();
reverse(q + 1, q + n + 1);
fft(q, dv, n << 1);
for (int i = 1; i <= n; i++)
printf("%.2lf\n", (ans[i] -= f[n - i + 1].real()));
}

posted @ 2019-08-31 09:29  洛水·锦依卫  阅读(173)  评论(0编辑  收藏  举报