https://scut.online/p/271

第一次遇到没这么裸的,其实感觉到是卷积但是不知道怎么化。看来以后要多注意下标。

#include <bits/stdc++.h>
using namespace std;
typedef long long ll; const int MAXN = 2e6;
const double PI = acos(-1.0); struct Complex {
double x, y;
Complex() {}
Complex(double x, double y): x(x), y(y) {}
friend Complex operator+(const Complex &a, const Complex &b) {
return Complex(a.x + b.x, a.y + b.y);
}
friend Complex operator-(const Complex &a, const Complex &b) {
return Complex(a.x - b.x, a.y - b.y);
}
friend Complex operator*(const Complex &a, const Complex &b) {
return Complex(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x);
}
} A[MAXN + 5], B[MAXN + 5]; void FFT(Complex a[], int n, int op) {
for(int i = 1, j = n >> 1; i < n - 1; ++i) {
if(i < j)
swap(a[i], a[j]);
int k = n >> 1;
while(k <= j) {
j -= k;
k >>= 1;
}
j += k;
}
for(int len = 2; len <= n; len <<= 1) {
Complex wn(cos(2.0 * PI / len), sin(2.0 * PI / len)*op);
for(int i = 0; i < n; i += len) {
Complex w(1.0, 0.0);
for(int j = i; j < i + (len >> 1); ++j) {
Complex u = a[j], t = a[j + (len >> 1)] * w ;
a[j] = u + t, a[j + (len >> 1)] = u - t;
w = w * wn;
}
}
}
if(op == -1) {
for(int i = 0; i < n; ++i)
a[i].x = (int)(a[i].x / n + 0.5);
}
} int pow2(int x) {
int res = 1;
while(res < x)
res <<= 1;
return res;
} void convolution(Complex A[], Complex B[], int Asize, int Bsize) {
int n = pow2(Asize + Bsize - 1);
for(int i = 0; i < n; ++i) {
A[i].y = 0.0;
B[i].y = 0.0;
}
for(int i = Asize; i < n; ++i)
A[i].x = 0;
for(int i = Bsize; i < n; ++i)
B[i].x = 0;
FFT(A, n, 1);
FFT(B, n, 1);
for(int i = 0; i < n; ++i)
A[i] = A[i] * B[i];
FFT(A, n, -1);
return;
} ll ans[MAXN+5],ans0; int main() {
#ifdef Yinku
freopen("Yinku.in", "r", stdin);
#endif // Yinku
int n, m;
scanf("%d%d", &n, &m);
for(int i = 0; i < n; ++i) {
scanf("%lf", &A[i].x);
}
for(int i = 0; i < n; ++i) {
scanf("%lf", &B[i].x);
}
reverse(B,B+n);
convolution(A, B, n, n);
for(int i=0;i<(n<<1);++i){
ans[i]=(ll)round(A[i].x);
//printf("%lld\n",ans[i]);
}
while(m--){
int k;
scanf("%d",&k);
if(k==0)
printf("%lld\n",ans[n-1]);
else
printf("%lld\n",ans[n-1-k]+ans[n-1+k]);
}
return 0;
}

最新文章

  1. Linux Epoll相关知识
  2. 在Entity Framework 7中进行数据迁移
  3. 如何在postgresql中模拟oracle的dual表,来测试数据库最基本的连接功能?
  4. 【Origin】 偶题 之 抒意
  5. JavaWeb学习篇之----容器Response详解
  6. Android如何在ListView中嵌套ListView
  7. 【Nutch2.2.1基础教程之6】Nutch2.2.1抓取流程
  8. MongoDB学习之--增删改查(1)
  9. Java面试常考------------------------垃圾收集算法
  10. Android WebView基本使用
  11. 微信小程序之获取用户位置权限(拒绝后提醒)
  12. vscode中tab键无法触发emmet快捷生成
  13. webstorm 支持vue element-ui 语法高亮属性自动补全
  14. MongoDB数据库基本命令
  15. SVN Attempted to lock an already-locked dir异常解决方法
  16. ASP.NET MVC中有四种过滤器类型
  17. java第一次考试
  18. 【OpenGL】纹理(Texture)
  19. 【转】MySQL安全配置介绍
  20. msys2 显示git branch

热门文章

  1. 机器学习中的偏差(bias)和方差(variance)
  2. php array_keys()函数 语法
  3. CSS中的 , &gt; + ~
  4. POJ 3111 K Best ( 二分 )
  5. layer.confirm
  6. 小程序封装wx.request,以及调用
  7. es之java搜索文档
  8. es之IK分词器
  9. java 线程池的创建方式
  10. 分类汇总统计mysql数据库一个字段中不同的记录的总和