link :
Method: fft+ principle of tolerance and repulsion
parsing:
this thing is actually an exponential parent function.
so the value we're just starting to read is that we put the coefficients in front of it to 1.
and then it's actually a polynomial multiplication.
The maximum range is obviously the maximum value in the Read value multiplied by three, for the subject is 12W.
using FFT to optimize the words, reached O (Nlogn), obviously can be passed.
But here's the question of how to handle the repetitive parts.
repeat the part we consider to solve with the principle of tolerance.
to facilitate the description we may wish to set three polynomials.
the first is a polynomial consisting of only one. ->x
The second is a polynomial that takes only the same two. ->y
The third is a polynomial consisting of only the same three. ->z
There are three kinds of situations for the subject.
The first is to take one, and obviously add x directly to the answer.
The second is to take two, a small step to be dismissed, that is (x*x-y)/2
The third is to take three, you need to further allow, that is, (x*x*x-3*x*y+2*z)/6
As for the third, a simple explanation, will be x*x*x on behalf of all the three cases, minus 3*x*y is actually minus a x*y/2, that is, two the same divided by the number of permutations, because the big situation is 3! Repeat, so add a coefficient, minus two of the same certainly contains three identical, So I'm going to add two of them back.
The final statistical answer can be.
Code:
#include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <
algorithm> #define N 131072 #define PI ACOs ( -1) using namespace std;
int n;
struct complex {double r,i;
Complex (double x=0.0,double y=0.0) {r=x,i=y;}
Complex operator + (const complex a) {return complex (a.r+r,a.i+i);}
Complex operator-(const complex a) {return complex (R-A.R,I-A.I);} Complex operator * (const complex a) {return complex (R*A.R-I*A.I,R*A.I+I*A.R);}}
A[N+10],B[N+10],C[N+10],D[N+10];
int rev[n+10];
void FFT (complex *a,int f) {for (int i=0;i<n;i++) if (i<rev[i)) swap (a[i],a[rev[i]);
for (int h=2;h<=n;h<<=1) {Complex wn (cos (2*pi*f/h), sin (2*pi*f/h));
for (int i=0;i<n;i+=h) {complex W (1,0);
for (int j=0;j< (h>>1); j++,w=w*wn) {complex t=a[i+j+ (h>>1)]*w;
a[i+j+ (h>>1)]=a[i+j]-t; a[I+j]=a[i+j]+t;
}} if (F==-1) for (int i=0;i<n;i++) a[i].r/=n;
int main () {int ma=-1;
scanf ("%d", &n); n--;
for (int i=0;i<=n;i++) {int x;
scanf ("%d", &x);
A[x].r=1,b[2*x].r=1,c[3*x].r=1;
Ma=max (MA,3*X);
int m=ma,l=0;
for (n=1;n<=m;n<<=1) l++; for (int i=0;i<n;i++) rev[i]= (rev[i>>1]>>1) |
((i&1) << (L-1));
FFT (a,1), FFT (b,1), FFT (c,1);
for (int i=0;i<=n;i++) {complex TMP (1.0/6.0,0);
Complex TMP2 (3.0,0);
Complex Tmp3 (2.0,0);
Complex Tmp4 (1.0/2.0,0);
d[i]=d[i]+ (A[i]*a[i]*a[i]-tmp2*a[i]*b[i]+tmp3*c[i]) *tmp;
d[i]=d[i]+ (A[i]*a[i]-b[i]) *tmp4;
D[i]=d[i]+a[i];
FFT (d,-1);
for (int i=0;i<=n;i++) {int print= (int) (d[i].r+0.1);
if (print!=0) printf ("%d%d\n", i,print); }
}