#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const int maxn=;
const double PI=acos(-);
struct node{
double real,imag;
void clear(){real=imag=;}
node operator +(const node &x){return (node){real+x.real,imag+x.imag};}
node operator -(const node &x){return (node){real-x.real,imag-x.imag};}
node operator *(const node &x){return (node){real*x.real-imag*x.imag,real*x.imag+imag*x.real};}
}a[maxn],b[maxn],c[maxn],t1,t2,w,wn;
int m,n,len,rev[maxn],ans[maxn];
void read(int &x){
x=; int f=; char ch;
for (ch=getchar();!isdigit(ch);ch=getchar()) if (ch=='-') f=-;
for (;isdigit(ch);ch=getchar()) x=x*+ch-''; x*=f;
}
int Rev(int x){
int temp=;
for (int i=;i<=len;i++) temp<<=,temp+=(x&),x>>=;
return temp;
}
void FFT(node *a,int op){
for (int i=;i<n;i++) if (i<rev[i]) swap(a[i],a[rev[i]]);
for (int s=;s<=n;s<<=){
wn=(node){cos(*op*PI/s),sin(*op*PI/s)};
for (int i=;i<n;i+=s){
w=(node){,};
for (int j=i;j<i+s/;j++,w=w*wn){
t1=a[j],t2=w*a[j+s/];
a[j]=t1+t2,a[j+s/]=t1-t2;
}
}
}
}
int main(){
read(m); n=,len=;
while (n<(m<<)) n<<=,len++;
for (int i=;i<n;i++) rev[i]=Rev(i);
for (int x,i=;i<m;i++) read(x),a[i].real=x,read(x),b[m--i].real=x;
FFT(a,),FFT(b,);
for (int i=;i<n;i++) c[i]=a[i]*b[i];
FFT(c,-);
for (int i=;i<n;i++) ans[i]=(int)round(c[i].real/n);
for (int i=m-;i<*m-;i++) printf("%d\n",ans[i]);
return ;
}

题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2194

题目大意:请计算C[k]=sigma(a[i]*b[i-k]) 其中 k < = i < n ,并且有 n < = 10 ^ 5。 a,b中的元素均为小于等于100的非负整数。

做法:考虑把b数组翻转,Ck的计算就成为了裸的卷积,对于这种题目,翻转是个重要的手段。

bzoj2194: 快速傅立叶之二的更多相关文章

  1. bzoj2194 快速傅立叶之二 ntt

    bzoj2194 快速傅立叶之二 链接 bzoj 思路 对我这种和式不强的人,直接转二维看. 发现对\(C_k\)贡献的数对(i,j),都是右斜对角线. 既然贡献是对角线,我们可以利用对角线的性质了. ...

  2. [bzoj2194]快速傅立叶之二_FFT

    快速傅立叶之二 bzoj-2194 题目大意:给定两个长度为$n$的序列$a$和$b$.求$c$序列,其中:$c_i=\sum\limits_{j=i}^{n-1} a_j\times b_{j-i} ...

  3. BZOJ2194:快速傅立叶之二(FFT)

    Description 请计算C[k]=sigma(a[i]*b[i-k]) 其中 k < = i < n ,并且有 n < = 10 ^ 5. a,b中的元素均为小于等于100的非 ...

  4. 2018.11.18 bzoj2194: 快速傅立叶之二(fft)

    传送门 模板题. 将bbb序列反过来然后上fftfftfft搞定. 代码: #include<bits/stdc++.h> #define ri register int using na ...

  5. bzoj千题计划256:bzoj2194: 快速傅立叶之二

    http://www.lydsy.com/JudgeOnline/problem.php?id=2194 相乘两项的下标 的 差相同 那么把某一个反过来就是卷积形式 fft优化 #include< ...

  6. BZOJ2194: 快速傅立叶之二(NTT,卷积)

    Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 1776  Solved: 1055[Submit][Status][Discuss] Descript ...

  7. BZOJ2194 快速傅立叶之二 【fft】

    题目 请计算C[k]=sigma(a[i]*b[i-k]) 其中 k < = i < n ,并且有 n < = 10 ^ 5. a,b中的元素均为小于等于100的非负整数. 输入格式 ...

  8. BZOJ2194: 快速傅立叶之二 FFT_卷积

    Code: #include <cstdio> #include <algorithm> #include <cmath> #include <cstring ...

  9. 【BZOJ2194】快速傅立叶之二

    [BZOJ2194]快速傅立叶之二 Description 请计算C[k]=sigma(a[i]*b[i-k]) 其中 k < = i < n ,并且有 n < = 10 ^ 5. ...

随机推荐

  1. 版本管理工具SVN

    此文件根据慕课网 源生活老师的教学视频总结 视频地址 http://www.imooc.com/learn/109 一.SVN下载和安装配置 服务端下载地址 https://www.visualsvn ...

  2. 压缩Sqlite数据文件大小,解决数据删除后占用空间不变的问题

    最近有一网站使用Sqlite数据库作为数据临时性的缓存,对多片区进行划分 Sqlite数据库文件,每天大概新增近1万的数据量,起初效率有明显的提高,但历经一个多月后数据库文件从几K也上升到了近160M ...

  3. Oracle创建表空间、创建用户以及授权

    Oracle安装完后,其中有一个缺省的数据库,除了这个缺省的数据库外,我们还可以创建自己的数据库. 为了避免麻烦,可以用’Database Configuration Assistant’向导来创建数 ...

  4. C# 6.0新特性---语法糖

    转载:http://www.cnblogs.com/TianFang/p/3928172.html 所谓语法糖就是在编译器里写做文章,达到简化代码书写的目的,要慎重使用,省略过多不易理解. NULL检 ...

  5. MS SQL 监控错误日志的告警信息

    SQL Server的错误消息(Error Message)按照消息的严重级别一共划分25个等级,级别越高,表示严重性也越高.但是如果你统计sys.messages,你会发现,实际上只有16(SQL ...

  6. MongoDB学习笔记~Mongo集群和副本集

    回到目录 一些概念 对于Mongo在数据容灾上,推荐的模式是使用副本集模式,它有一个对外的主服务器Primary,还有N个副本服务器Secondary(N>=1,当N=1时,需要有一台仲裁服务器 ...

  7. netty4虚拟内存不断飙升

    去年升级过一个老的netty3的程序到netty4,近期突然注意到一个问题,就是这个程序随着时间虚拟内存会不断升高.之前升级的时候担心存在内存泄露,所以还特意用jstate跟踪过gc回收的情况,并没有 ...

  8. [转]ASP.NET Core 中间件详解及项目实战

    本文转自:http://www.cnblogs.com/savorboard/p/5586229.html 前言 在上篇文章主要介绍了DotNetCore项目状况,本篇文章是我们在开发自己的项目中实际 ...

  9. python 聊天室

    server端程序 # -*- coding: utf-8 -*- #!/usr/bin/python """ """ import soc ...

  10. springboot Serving Web Content with Spring MVC

    Serving Web Content with Spring MVC This guide walks you through the process of creating a "hel ...