# Triple

## Description

“这把斧头，是不是你的？”

“这把斧头，是不是你的？”

“这把斧头，是不是你的？”

“你看看你现在的样子，真是丑陋！”

## HINT

（这玩意好像叫做生成函数）

#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
const int N=270005;
const double pi=3.141592653589793;
int n,m,x,rev[N];
long long ans;
struct complex{
double x,y;
complex(){
x=y=0;
}
complex(double x,double y):x(x),y(y){}
friend complex operator + (const complex &a,const complex &b){
return complex(a.x+b.x,a.y+b.y);
}
friend complex operator - (const complex &a,const complex &b){
return complex(a.x-b.x,a.y-b.y);
}
friend complex operator * (const complex &a,const complex &b){
return complex(a.x*b.x-a.y*b.y,a.x*b.y+a.y*b.x);
}
friend complex operator * (const complex &a,const double &b){
return complex(a.x*b,a.y*b);
}
friend complex operator / (const complex &a,const double &b){
return complex(a.x/b,a.y/b);
}
}a[N],b[N],c[N];
void fft(complex *a,int dft){
for(int i=0;i<n;i++){
if(i<rev[i]){
swap(a[i],a[rev[i]]);
}
}
for(int i=1;i<n;i<<=1){
complex wn=complex(cos(pi/i),dft*sin(pi/i));
for(int j=0;j<n;j+=i<<1){
complex w=complex(1,0),x,y;
for(int k=j;k<j+i;k++,w=w*wn){
x=a[k];
y=w*a[k+i];
a[k]=x+y;
a[k+i]=x-y;
}
}
}
if(dft==-1){
for(int i=0;i<n;i++){
a[i]=a[i]/n;
}
}
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&x);
a[x].x++;
b[2*x].x++;
c[3*x].x++;
m=max(m,3*x);
}
for(n=1;n<=m;n<<=1);
for(int i=0;i<n;i++){
rev[i]=(rev[i>>1]>>1)|((i&1)*(n>>1));
}
fft(a,1);
fft(b,1);
fft(c,1);
for(int i=0;i<n;i++){
a[i]=a[i]+(a[i]*a[i]-b[i])/2+(a[i]*a[i]*a[i]-a[i]*b[i]*3+c[i]*2)/6;
}
fft(a,-1);
for(int i=0;i<n;i++){
ans=(long long)(a[i].x+0.5);
if(ans){
printf("%d %lld\n",i,ans);
}
}
return 0;
}
posted @ 2018-04-19 22:26  ez_2016gdgzoi471  阅读(85)  评论(0编辑  收藏  举报