[ZJOI 2014]力

Description

给出n个数qi,给出Fj的定义如下:
$$F_j = \sum_{i<j}\frac{q_i q_j}{(i-j)^2 }-\sum_{i>j}\frac{q_i q_j}{(i-j)^2 }$$
令Ei=Fi/qi,求Ei.

Input

第一行一个整数n。
接下来n行每行输入一个数,第i行表示qi。
n≤100000,0<qi<1000000000

Output

 n行,第i行输出Ei。与标准答案误差不超过1e-2即可。

Sample Input

5
4006373.885184
15375036.435759
1717456.469144
8514941.004912
1410681.345880

Sample Output

-16838672.693
3439.793
7509018.566
4595686.886
10903040.872

题解

约掉 $q_i$ $$E_j = \sum_{i<j}\frac{q_j}{(i-j)^2 }-\sum_{i>j}\frac{q_j}{(i-j)^2 }$$

我们拿出 $A_i=\sum\limits_{i<j}\frac{q_j}{(i-j)^2 }$ 讨论。

构造第一个多项式系数依次为 $q_i,i\in[0,n)$ ,第二个多项式系数 $\begin{cases}0 &i=0\\ \frac{1}{i^2} &i\in[1,n)\end{cases}$

卷积之后第 $i$ 项就是所求的 $A_i$ 。之后的类似,对于 $A'_i=\sum\limits_{i>j}\frac{q_j}{(i-j)^2 }$ 只要把第一个多项式翻转,卷积后第 $n-1-i$ 项就是所求的 $A'_i$ 。

 1 //It is made by Awson on 2018.1.28
 2 #include <set>
 3 #include <map>
 4 #include <cmath>
 5 #include <ctime>
 6 #include <queue>
 7 #include <stack>
 8 #include <cstdio>
 9 #include <string>
10 #include <vector>
11 #include <complex>
12 #include <cstdlib>
13 #include <cstring>
14 #include <iostream>
15 #include <algorithm>
16 #define LL long long
17 #define dob complex<double>
18 #define Abs(a) ((a) < 0 ? (-(a)) : (a))
19 #define Max(a, b) ((a) > (b) ? (a) : (b))
20 #define Min(a, b) ((a) < (b) ? (a) : (b))
21 #define Swap(a, b) ((a) ^= (b), (b) ^= (a), (a) ^= (b))
22 #define writeln(x) (write(x), putchar('\n'))
23 #define lowbit(x) ((x)&(-(x)))
24 using namespace std;
25 const int N = 100000*4;
26 const double pi = acos(-1.0);
27 
28 int n, m, s, L, R[N+5];
29 double q[N+5], sum, ans[N+5];
30 dob a[N+5], b[N+5];
31 
32 void FFT(dob *A, int o) {
33     for (int i = 0; i < n; i++) if (i > R[i]) swap(A[i], A[R[i]]);
34     for (int i = 1; i < n; i <<= 1) {
35     dob wn(cos(pi/i), sin(pi*o/i)), x, y;
36     for (int j = 0; j < n; j += (i<<1)) {
37         dob w(1, 0);
38         for (int k = 0; k < i; k++, w *= wn) {
39         x = A[j+k], y = w*A[i+j+k];
40         A[j+k] = x+y, A[i+j+k] = x-y;
41         }
42     }
43     }
44 }
45 void work() {
46     scanf("%d", &n); n--; s = n;
47     for (int i = 0; i <= n; i++) scanf("%lf", &q[i]), a[i] = q[i];
48     for (int i = 1; i <= n; i++) b[i] = 1./i/i;
49     m = n<<1; for (n = 1; n <= m; n <<= 1) L++;
50     for (int i = 0; i < n; i++) R[i] = (R[i>>1]>>1)|((i&1)<<(L-1));
51     FFT(a, 1), FFT(b, 1);
52     for (int i = 0; i <= n; i++) a[i] *= b[i];
53     FFT(a, -1);
54     for (int i = 0; i <= s; i++) ans[i] = a[i].real()/n;
55     for (int i = 0; i <= n; i++) a[i] = 0;
56     for (int i = 0; i <= s; i++) a[i] = q[s-i];
57     FFT(a, 1);
58     for (int i = 0; i <= n; i++) a[i] *= b[i];
59     FFT(a, -1);
60     for (int i = 0; i <= s; i++) printf("%lf\n", ans[i]-a[s-i].real()/n);
61 }
62 int main() {
63     work();
64     return 0;
65 }

 

posted @ 2018-01-28 22:26  NaVi_Awson  阅读(197)  评论(0编辑  收藏  举报