bzoj4827:[Hnoi2017]礼物

传送门

$\sum_{i=1}^{n}(a_i+x-b_i)^2\\ =\sum_{i=1}^{n}(a_i^2+b_i^2+x^2+2a_ix-2b_ix-2a_ib_i)\\ =\sum_{i=1}^{n}(a_i^2+b_i^2)+nx^2+2x\sum_{i=1}^{n}(a_i-b_i)-2\sum_{i=1}^{n}a_ib_i$

$2\sum_{i=1}^{n}a_{n-i+1}b_i$

    #include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
char ch; bool ok;
for(ok=0,ch=getchar(); !isdigit(ch); ch=getchar()) if(ch=='-') ok=1;
for(x=0; isdigit(ch); x=x*10+ch-'0',ch=getchar()); if(ok) x=-x;
}
#define rg register
const int maxn=4e5+10;const double pi=acos(-1);
struct complex{double x,y;}a[maxn*2],b[maxn];
int n,m,nn,ans,sum,w,len,r[maxn];double tot;
complex operator-(complex a,complex b){return (complex){a.x-b.x,a.y-b.y};}
complex operator+(complex a,complex b){return (complex){a.x+b.x,a.y+b.y};}
complex operator*(complex a,complex b){return (complex){a.x*b.x-a.y*b.y,a.y*b.x+b.y*a.x};}
void fft(complex *a,int f)
{
for(rg int i=0;i<n;i++)if(r[i]>i)swap(a[r[i]],a[i]);
for(rg int i=1;i<n;i<<=1)
{
complex wn=(complex){cos(pi/i),f*sin(pi/i)};
for(rg int j=0;j<n;j+=(i<<1))
{
complex w=(complex){1,0};
for(rg int k=0;k<i;k++)
{
complex x=a[j+k],y=w*a[j+k+i];
a[j+k]=x+y,a[j+k+i]=x-y,w=w*wn;
}
}
}
if(f==-1)for(rg int i=0;i<=m;i++)a[i].x=a[i].x/n+0.5;
}
int main()
{
}