[BZOJ-3527]力

Description

给出n个数q[i],给出F[j]的定义如下:
F[j] = sigma(q[i] q[j] / (i - j) ^ 2) (i < j) - sigma(q[i] q[j] / (i - j) ^ 2) (i > j)
令E[i] = F[i] / q[i],求E[i]。

Solution

这是一道[ZJOI2014]的题。
E[j] = F[j] / q[j] = sigma(q[i] / (i - j) ^ 2) (i < j) - sigma(q[i] / (i - j) ^ 2) (i > j)
我们令T[x] = x > 0 ? 1 / x ^ 2 : -1 / x ^ 2
那么E[j] = sigma(q[i] * T[j - i])
转化为卷积的形式后,只要FFT就可以得出结果了。

Notice

要注意T的下标有负数,要同时加上一个数使得下标都变为正数。

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define sqz main
#define ll long long
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define Rep(i, a, b) for (int i = (a); i < (b); i++)
#define travel(i, u) for (int i = head[u]; ~i; i = edge[i].next)

const ll INF = 1e9, Mo = INF + 7;
const int N = 530000;
const double eps = 1e-6, pi = acos(-1.0);
ll read()
{
ll x = 0; int zf = 1; char ch = getchar();
while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
if (ch == '-') zf = -1, ch = getchar();
while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
return x * zf;
}
void write(ll y)
{
if (y < 0) putchar('-'), y = -y;
if (y > 9) write(y / 10);
putchar(y % 10 + '0');
}

int Rev[N + 5];
struct Complex
{
double real, imagine;
Complex (double real = 0, double imagine = 0) : real(real), imagine(imagine) {}
Complex operator +(const Complex X)
{
return Complex(real + X.real, imagine + X.imagine);
}
Complex operator -(const Complex X)
{
return Complex(real - X.real, imagine - X.imagine);
}
Complex operator *(const Complex X)
{
return Complex(real * X.real - imagine * X.imagine, real * X.imagine + imagine * X.real);
}
}X[N + 5], Y[N + 5];

void FFT(Complex *T, int n, int op)
{
Rep(i, 0, n) if (i < Rev[i]) swap(T[i], T[Rev[i]]);
for (int Size = 1; Size < n; Size <<= 1)
{
Complex wn = Complex(cos(pi / Size), sin(pi / Size) * op);
for (int L = 0; L < n; L += (Size << 1))
{
Complex w = Complex(1, 0);
Rep(R, L, L + Size)
{
Complex x = T[R], y = w * T[R + Size];
T[R] = x + y, T[R + Size] = x - y;
w = w * wn;
}
}
}
}

int sqz()
{
int n = read() - 1;
rep(i, 0, n) scanf("%lf", &X[i].real);
Y[n] = 0;
rep(i, 1, n) Y[n + i] = 1.0 / ((double)i * i), Y[n - i] = -1.0 / ((double)i * i);
int x = 3 * n;
int t, l = 0; for (t = 1; t <= x; t <<= 1) l++;
Rep(i, 0, t) Rev[i] = (Rev[i >> 1] >> 1) + ((i & 1) << l - 1);
FFT(X, t, 1); FFT(Y, t, 1);
Rep(i, 0, t) X[i] = X[i] * Y[i];
FFT(X, t, -1);
rep(i, n, 2 * n) printf("%.3lf\n", X[i].real / t);
return 0;
}
文章目录
  1. 1. Description
  2. 2. Solution
  3. 3. Notice
  4. 4. Code