HDU-5307 He is Flying (FFT)
Problem Description
JRY wants to drag racing along a long road. There are n sections on the road, the i -th section has a non-negative integer length si .
JRY will choose some continuous sections to race (at an unbelievable speed), so there are totally n(n+1)2 different ways for him to ride.
If JRY rides across from the i -th section to the j -th section, he would gain j?i+1 pleasure. Now JRY wants to know, if he tries all the ways whose length is s ,
what's the total pleasure he can get. Please be aware that in the problem, the length of one section could be zero, which means that the length is so trivial that we can regard it as 0
Input
The first line of the input is a single integer T (T=5) , indicating the number of testcases.
For each testcase, the first line contains one integer n . The second line contains n non-negative integers,
which mean the length of every section. If we denote the total length of all the sections as s , we can guarantee that 0≤s≤50000 and 1≤n≤100000 .
Output
For each testcase, print s+1 lines. The single number in the i -th line indicates the total pleasure JRY can get if he races all the ways of length i?1 .
Sample Input
2 3 1 2 3 4 0 1 2 3
Sample Output
0 1 1 3 0 2 3 1 3 1 6 0 2 7
#include<cmath>
#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int DLT=;
const long double PI=acos(-1.0);
struct cp{
long double x,y;
cp(){}
cp(long double a,long double b){x=a;y=b;}
cp friend operator + (cp a,cp b){return cp(a.x+b.x,a.y+b.y);}
cp friend operator - (cp a,cp b){return cp(a.x-b.x,a.y-b.y);}
cp friend operator * (cp a,cp b){return cp(a.x*b.x-a.y*b.y,a.x*b.y+a.y*b.x);}
}A[],B[],C[],D[];
int T;
int n,m;
int lim;
int len;
int s[];
int pos[];
int sum[];
void init(void)
{
memset(A,,sizeof(A));
memset(B,,sizeof(B));
memset(C,,sizeof(C));
memset(D,,sizeof(D));
return ;
}
void FFT(cp *a,double flag)
{
for(int i=;i<len;i++)if(i<pos[i])std::swap(a[i],a[pos[i]]);
for(int i=;i<=len;i<<=)
{
cp wn(cos(2.00*flag*PI/i),sin(2.00*flag*PI/i));
for(int j=;j<len;j+=i)
{
cp w(,),t;
for(int k=;k<(i>>);k++,w=w*wn)
{
t=a[j+k+(i>>)]*w;
a[j+k+(i>>)]=a[j+k]-t;
a[j+k]=a[j+k]+t;
}
}
}
return ;
}
void work(void)
{
init();
long long a0();
int cnt();
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d",&s[i]);
if(!s[i])
{
cnt++;
a0+=1ll*cnt*(cnt+)/;
}else cnt=;
sum[i]=sum[i-]+s[i];
}
printf("%lld\n",a0);
while((<<lim)<(DLT<<))lim++;len=<<lim;
for(int i=;i<len;i++)pos[i]=(pos[i>>]>>)|((i&)<<(lim-));
for(int i=;i<=n;i++)
{
A[sum[i]].x+=i;B[DLT-sum[i-]].x+=;
C[sum[i]].x+=;D[DLT-sum[i-]].x+=i-;
}
FFT(A,),FFT(B,),FFT(C,),FFT(D,);
for(int i=;i<len;i++)A[i]=A[i]*B[i]-C[i]*D[i];
FFT(A,-);
for(int i=;i<=sum[n];i++)printf("%I64d\n",(long long)(A[i+DLT].x/len+0.2));
return ;
}
int main()
{
scanf("%d",&T);
while(T --> )work();
return ;
}
HDU-5307 He is Flying (FFT)的更多相关文章
- HDU 5307 He is Flying ——FFT
卷积的妙用,显然我们可以求出所有符合条件的右端点的和,然后减去左端点的和. 就是最后的答案.然后做一次前缀和,然后就变成了统计差是一个定值的情况. 令$A(s[i])++$ $B(s[i])+=i$ ...
- FFT(快速傅里叶变换):HDU 5307 He is Flying
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAA8IAAAPeCAIAAABInTQaAAAgAElEQVR4nOy9fZReVXk3vP8ia+HqCy
- HDU 5307 He is Flying (生成函数+FFT)
题目传送门 题目大意:给你一个长度为$n$的自然数序列$a$,定义一段区间的权值为这一段区间里所有数的和,分别输出权值为$[0,\sum a_{i}]$的区间的长度之和 想到了生成函数的话,这道题并不 ...
- HDU - 5307 :He is Flying (分治+FFT)(非正解)
JRY wants to drag racing along a long road. There are nn sections on the road, the ii-th section has ...
- HDU 5515 Game of Flying Circus 二分
Game of Flying Circus Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem ...
- HDU 5763 Another Meaning(FFT)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5763 [题目大意] 给出两个串S和T,可以将S串中出现的T替换为*,问S串有几种表达方式. [题解 ...
- hdu 4656 Evaluation [任意模数fft trick]
hdu 4656 Evaluation 题意:给出\(n,b,c,d,f(x) = \sum_{i=1}^{n-1} a_ix^i\),求\(f(b\cdot c^{2k}+d):0\le k < ...
- hdu 5730 Shell Necklace [分治fft | 多项式求逆]
hdu 5730 Shell Necklace 题意:求递推式\(f_n = \sum_{i=1}^n a_i f_{n-i}\),模313 多么优秀的模板题 可以用分治fft,也可以多项式求逆 分治 ...
- hdu 5730 Shell Necklace —— 分治FFT
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5730 DP式:\( f[i] = \sum\limits_{j=1}^{i} f[i-j] * a[j] ...
- hdu 4609 3-idiots(快速傅里叶FFT)
比较裸的FFT(快速傅里叶变换),也是为了这道题而去学的,厚的白书上有简单提到,不过还是推荐看算法导论,讲的很详细. 代码的话是照着别人敲的,推荐:http://www.cnblogs.com/kua ...
随机推荐
- 洛谷——P2661 信息传递
https://www.luogu.org/problem/show?pid=2661#sub 题目描述 有n个同学(编号为1到n)正在玩一个信息传递的游戏.在游戏里每人都有一个固定的信息传递对象,其 ...
- HDOJ 2828 Lamp DLX反复覆盖
DLX反复覆盖模版题: 每一个开关两个状态.但仅仅能选一个,建2m×n的矩阵跑DLX模版.. .. Lamp Time Limit: 2000/1000 MS (Java/Others) Mem ...
- RISC-V首度被我国列入扶持对象,上海已成RISC-V重要“据点”
时间:2018年7月24日 16:33 摘要:近期,上海市经济信息委发布了<上海市经济信息化委关于开展2018年度第二批上海市软件和集成电路产业发展专项资金(集成电路和电子信息制造领域)项目申报 ...
- 关于有的Apk无法反编译的探究
Android的apk包,其实就是zip包,只不过后缀名换了而已!使用“好压”等解压缩工具解压,就可以看到里面的内容了.简单介绍一下吧. 以下就是解压出来的apk的内容: 其中: assets ...
- Keyboard input
Keyboard input Python provides a build-in function called raw_input (in version 2.x) that gets input ...
- Hadoop框架基础(一)
** Hadoop框架基础(一) 学习一个新的东西,传统而言呢,总喜欢漫无目的的扯来扯去,比如扯扯发展史,扯扯作者是谁,而我认为这些东西对于刚开始接触,并以开发为目的学者是没有什么帮助的,反而 ...
- Swift学习笔记(1):基础部分
目录: 分号 常量和变量 数据类型 数值型类型转换 类型别名 元组 可选类型 API版本检查 分号 Swift并不强制要求你在每条语句的结尾处使用分号( ; ),你也可以按照自己的习惯添加分号.如果在 ...
- 提高realm存储速率
我的数据量大约有2.5M,但是完全存储到数据库差不多用了11秒,有没有比较好的方法提高存储效率 提高realm存储速率 >> android这个答案描述的挺清楚的:http://www.g ...
- unbuntu禁用ipv6
ubuntu禁用ipv6cat /proc/sys/net/ipv6/conf/all/disable_ipv6 显示0说明ipv6开启,1说明关闭 在 /etc/sysctl.conf 增加下面几行 ...
- Goldengate参数规范
1. 文档综述 1.1. 文档说明 本文档规定了在实施Goldengate时,各个进程需要配置的参数. 该参数模板适合于Goldengate11.2.1.0版本: **注:本文档为Golden ...