0≤i≤sn0≤i≤sn,求所有和为i的子区间的长度和。" type="text/javascript">
频道栏目
首页 > 资讯 > 其他 > 正文

He is Flying FFT

18-04-11        来源:[db:作者]  
收藏   我要投稿

题意

给出一个长度为n的非负整数序列a,设s表示a的前缀和,对于所有的0isn" role="presentation">0isn,求所有和为i的子区间的长度和。
n105,sn5104" role="presentation">n105,sn5?104

分析

看到这种不管怎么暴力搞都要O(n2)" role="presentation">O(n2)的题目就应该想到FFT了。
这个构造还是比较巧妙的,不难发现答案就是(ixsi)(xsi1)(xsi)((i1)xsi1)" role="presentation">(ixsi)(x?si?1)?(xsi)((i?1)x?si?1)
直接大力FFT就好了。
其中i=0" role="presentation">i=0的答案要特殊算。

代码

#include
#include
#include
#include
#include
#include
using namespace std;

typedef long long LL;
typedef long double ldb;

const int N=100005;
const ldb pi=acos(-1.0);

int n,s[N],L,rev[N*2];
LL ans[N],sum[N];
struct com
{
    ldb x,y;
    com operator + (const com &d) const {return (com){x+d.x,y+d.y};}
    com operator - (const com &d) const {return (com){x-d.x,y-d.y};}
    com operator * (const com &d) const {return (com){x*d.x-y*d.y,x*d.y+y*d.x};}
    com operator / (const ldb &d) const {return (com){x/d,y/d};}
}a[N*2],b[N*2];

int read()
{
    int x=0,f=1;char ch=getchar();
    while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

void FFT(com *a,int f)
{
    for (int i=0;i>1]>>1)|((i&1)<<(lg-1));
        for (int i=s[n]+1;i
   
相关TAG标签
上一篇:windows如何实现开机自动执行.bat脚本?
下一篇:python下format函数基础用法介绍
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站