题目链接

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

设\(A[i]=q[i]\),\(B[i]=\frac{1}{i^2}\),\(A\times B\)就能得到第一个\(\sum\),把\(A\)反过来再\(\times B\)就能得到第二个\(\sum\),相减即可。

用\(FFT\)算。

#include <cstdio>
#include <cmath>
#include <algorithm>
#define re register
using namespace std;
const int MAXN = 300010;
const double PI = M_PI;
struct complex{
double x, y;
complex(double xx = 0, double yy = 0){ x = xx; y = yy; }
}a[MAXN], b[MAXN];
inline complex operator + (complex a, complex b){
return complex(a.x + b.x, a.y + b.y);
}
inline complex operator - (complex a, complex b){
return complex(a.x - b.x, a.y - b.y);
}
inline complex operator * (complex a, complex b){
return complex(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x);
}
double q[MAXN], e[MAXN];
int r[MAXN], n, m;
void FFT(complex *f, int mode){
for(re int i = 0; i < m; ++i) if(i < r[i]) swap(f[i], f[r[i]]);
for(re int p = 2; p <= m; p <<= 1){
re int len = p >> 1;
re complex tmp(cos(PI / len), mode * sin(PI / len));
for(re int l = 0; l < m; l += p){
re complex w(1, 0);
for(re int k = l; k < l + len; ++k){
re complex t = w * f[len + k];
f[len + k] = f[k] - t;
f[k] = f[k] + t;
w = w * tmp;
}
}
}
}
int main(){
scanf("%d", &n);
for(re int i = 1; i <= n; ++i) scanf("%lf", &q[i]);
for(re int i = 1; i <= n; ++i) a[i].x = q[i], b[i].x = 1.0 / (1.0 * i * i);
for(m = 1; m <= (n << 1); m <<= 1);
for(re int i = 1; i < m; ++i) r[i] = r[i >> 1] >> 1 | ((i & 1) * (m >> 1));
FFT(a, 1); FFT(b, 1);
for(re int i = 0; i < m; ++i) a[i] = a[i] * b[i];
FFT(a, -1);
for(re int i = 1; i <= n; ++i) e[i] = a[i].x;
for(re int i = 0; i < m; ++i) a[i].x = b[i].x = a[i].y = b[i].y = 0;
for(re int i = 1; i <= n; ++i) a[i].x = q[n - i + 1], b[i].x = 1.0 / (1.0 * i * i);
FFT(a, 1); FFT(b, 1);
for(re int i = 0; i < m; ++i) a[i] = a[i] * b[i];
FFT(a, -1);
for(int i = 1; i <= n; ++i) printf("%.3lf\n", (e[i] - a[n - i + 1].x) / m);
return 0;
}

【洛谷 P3338】 [ZJOI2014]力(FFT)的更多相关文章

  1. [洛谷P3338] [ZJOI2014]力

    洛谷题目链接:P3338 [ZJOI2014]力 题目描述 给出n个数qi,给出Fj的定义如下: \[F_j = \sum_{i<j}\frac{q_i q_j}{(i-j)^2 }-\sum_ ...

  2. 洛谷 P3338 [ZJOI2014]力 解题报告

    P3338 [ZJOI2014]力 题目描述 给出n个数qi,给出Fj的定义如下: \(F_j = \sum_{i<j}\frac{q_i q_j}{(i-j)^2 }-\sum_{i>j ...

  3. 洛谷P3338 [ZJOI2014]力(FFT)

    传送门 题目要求$$E_i=\frac{F_i}{q_i}=\sum_{j=1}^{i-1}\frac{q_j}{(i-j)^2}-\sum_{j=i+1}^n\frac{q_j}{(j-i)^2}$ ...

  4. 洛谷 P3338 [ZJOI2014]力

    题意简述 读入\(n\)个数\(q_i\) 设\(F_j = \sum\limits_{i<j}\frac{q_i\times q_j}{(i-j)^2 }-\sum\limits_{i> ...

  5. [bzoj3527] [洛谷P3338] [Zjoi2014]力

    Description 给出n个数qi,给出Fj的定义如下: \[ F_j=\sum\limits_{i<j} \frac{q_iq_j}{(i-j)^2} - \sum\limits_{i&g ...

  6. P3338 [ZJOI2014]力(FFT)

    题目 P3338 [ZJOI2014]力 做法 普通卷积形式为:\(c_k=\sum\limits_{i=1}^ka_ib_{k-i}\) 其实一般我们都是用\(i=0\)开始的,但这题比较特殊,忽略 ...

  7. P3338 [ZJOI2014]力 /// FFT 公式转化翻转

    题目大意: https://www.luogu.org/problemnew/show/P3338 题解 #include <bits/stdc++.h> #define N 300005 ...

  8. 洛咕 P3338 [ZJOI2014]力

    好久没写过博客了.. 大力推式子就行了: \(E_i=\sum_{j<i}\frac{q_j}{(i-j)^2}+\sum_{j>i}\frac{q_j}{(j-i)^2}\) 那么要转化 ...

  9. [Luogu]P3338 [ZJOI2014]力(FFT)

    题目描述 给出\(n\)个数\(q_i\),给出\(F_j\)的定义如下: \(F_j = \sum_{i<j}\frac{q_i q_j}{(i-j)^2 }-\sum_{i>j}\fr ...

  10. 【洛谷P3338】力

    题目大意:求 \[ E_{j}=\sum_{i<j} \frac{q_{i}}{(i-j)^{2}}-\sum_{i>j} \frac{q_{i}}{(i-j)^{2}} \] 题解:可以 ...

随机推荐

  1. Oracle忘记密码如何重置

    昨天安装Oracle11g R2的时候给scott用户设置密码,当时没有显示而且还只以输入一次,可能密码输入错误,结果今天用scott用户登录果然密码不对,还好sys和system用户都正常,就进去给 ...

  2. QP(Quote-Printable) 编码

    QP(Quote-Printable)   方法,通常缩写为“Q”方法,其原理是把一个 8   bit   的字符用两个16进制数值表示,然后在前面加“=”.所以我们看到经过QP编码 后的文件通常是这 ...

  3. WCF跨时区自动转换问题

    背景:api端 用wcf做的 客户端是silverlight, 服务和消费 不是同一个时区 状况:客户端调用返回对象有个字段是datetime ,返回的时间和数据库相差好几个小时,找了很久,最后把da ...

  4. [乱搞]hdu 6406 Taotao picks apples 笛卡尔树+倍增

    题目链接 Problem Description There is an apple tree in front of Taotao's house. When autumn comes, n app ...

  5. iOS 监听键盘高度,输入框上升

    //设置输入框 ---<因为输入框用了get方法,所以第一次调用输入框要用self 调用>: self.textlab.frame=CGRectMake(, , , ); _textlab ...

  6. 51nod-1220-约数之和

    题意 求 \[ \sum _{i=1}^n\sum _{j=1}^nd(ij) \\ d(x)=\sum _{e|x}e \] \(n\le 10^9\) . 分析 没有推出来.这题有几个要点要学习. ...

  7. 多线程---handlerthread

    当我们需要工作线程来操作的时候,很多时候会有同步问题,UI更新问题. Handle机制就是为了解决这个问题而产生的. android允许每个线程都有自己的消息队列,同时也可以是主线程消息队列. 但是很 ...

  8. robot framework 安装

    一.安装 Python 2.7 pip 和 setuptools (Python 的套件管理程式,最新版的Python 2.7.13已包含) Robot Framework (此工具本身) wxPyt ...

  9. BZOJ2331:[SCOI2011]地板——题解

    http://www.lydsy.com/JudgeOnline/problem.php?id=2331 题面复制于洛谷 题目描述 lxhgww的小名叫”小L“,这是因为他总是很喜欢L型的东西.小L家 ...

  10. mysql允许远程特定ip访问

    1.登录 mysql -u root -p 之后输入密码进行登陆 2.权限设置及说明 2.1添加远程ip访问权限 GRANT ALL PRIVILEGES ON *.* TO 'root'@'10.1 ...