Description
Ask all three/two/tuple combinations that may be formed.
Sol
Fft.
Use the generated function to direct the FFT, and then the calculation, the calculation of the time to simply a little bit.
Any three -3* two identical +2* all the same + any two-two identical + any one.
Code
/************************************************************** problem:3771 User:beiyu language:c++ Result : Accepted time:1760 ms memory:26684 kb****************************************************************/#include &L T;bits/stdc++.h>using namespace Std; #define MPR Make_pair#define RR First#define II secondtypedef pair< double,double > complex;const int N = 5e5+50;con St int M = 40000;const double Pi = M_PI; Complex operator + (const Complex &a,const Complex &b) {return MPR (A.RR+B.RR,A.II+B.II);} Complex operator-(const Complex &a,const Complex &b) {return MPR (A.RR-B.RR,A.II-B.II);} Complex operator * (const Complex &a,const Complex &b) {return MPR (A.RR*B.RR-A.II*B.II,A.RR*B.II+A.II*B.RR);} Complex operator * (const Complex &a,const int &b) {return MPR (A.RR*B,A.II*B);} Complex operator/(const Complex &a,const double &b) {return MPR (a.rr/b,a.ii/b);} int n; Complex A[n],b[n],c[n];int Ans[n]; void Rev (Complex a[]) {for (int i=0,j=0;i<n;i++) {if (i>j) swap (a[i],a[j]); for (int k=n>>1; (j^=k) <k;k>>=1); }}void DFT (Complex a[],int R) {Rev (a); for (int i=2;i<=n;i<<=1) {Complex wi=mpr (cos (2.0*pi/i), R*sin (2.0*pi/i)); for (int k=0;k<n;k+=i) {Complex w=mpr (1.0,0.0); for (int j=k;j<k+i/2;j++) {Complex T1=A[J],T2=W*A[J+I/2]; A[j]=t1+t2,a[j+i/2]=t1-t2; W=w*wi; }}}if (R==-1) for (int i=0;i<n;i++) a[i].rr/=n;} void FFT (Complex a[],complex B[],complex c[]) {DFT (a,1), DFT (b,1); for (int i=0;i<n;i++) c[i]=a[i]*b[i]; DFT (c,-1);} void init (int x) {for (n=1;n<x;n<<=1);} void Print (Complex a[]) {for (int i=0;i<n;i++) if ((int) (a[i].rr+0.5) >=1) printf ("%d%d\n", I,int (a[i].rr+0.5));} int main () {int l; cin>>l; for (int i=1,x;i<=l;i++) cin>>x,a[x].rr+=1.0,b[x*2].rr+=1.0,c[x*3].rr+=1.0; Init (m*3); DFT (a,1), DFT (b,1), DFT (c,1); for (int i=0;i<n;i++) a[i]= (a[i]*a[i]*a[i]-a[i]*b[i]*3+c[i]*2)/6.0+ (A[i]*a[i]-b[i])/2.0+a[i]; DFT (a,-1); Print (a); return 0;}
Bzoj 3771:triple