Triple sums (FFT modeling) __fft

Source: Internet
Author: User
Tags acos

Transmission Door

You ' re given a sequence s of N distinct integers.
Consider all the possible sums of three integers to the sequence at three different.
For each obtainable sum to output the number of different triples of indicies that generate it.

Constraints:

N <= 40000, |si| <= 20000 Input

The "a single integer N" of input contains.
Each of the next N-lines contain an element of S. Output

Print the solution for each possible sum in the following format:
Sum_value:number_of_triples

Smaller sum values should be printed. Example

Input:

5
-1
2
3
0
5
Output:

1:1
2:1
4:2
5:1
6:1
7:2
8:1
10:1

Explanation:
4 can be obtained using triples (0, 1, 2) and (0, 3, 4).
7 can be obtained using triples (0, 2, 4) and (1, 3, 4).

Note: a triple are considered the same as any of its permutations.


Description: Σx^2 to deal with, here means that the index is twice times the AI, then its coefficient is the number of x^2, is the number of AI, Σx^3 is the same, is three times times the AI. Another: C11 can not compile.

No.1 #pragma COMMENT (linker, "/stack:1024000000,1024000000") #include <vector> #include <iostream> #include <string> #include <map> #include <stack> #include <cstring> #include <queue> # Include <list> #include <stdio.h> #include <set> #include <algorithm> #include <cstdlib> # Include <cmath> #include <iomanip> #include <cctype> #include <sstream> #include <functional > #include <stdlib.h> #include <time.h> #include <bitset> #include <complex> using namespace s

td
#define PI ACOs ( -1) #define PI ACOs ( -1) #define Endl ' \ n ' #define Srand () Srand (Time (0));
#define ME (X,y) memset (x,y,sizeof (x)); #define foreach (It,a) for (__typeof ((a). Begin ()) it= (a). Begin (), it!= (a). End (), it++) #define Close () ios::sync_with_ Stdio (0);
Cin.tie (0);  #define for (x,n,i) for (int i=x;i<=n;i++) #define for (x,n,i) for (int i=x;i<n;i++) #define W while #define SGN (x) < 0? -1 : (x) > 0) #define Bug printf ("***********\n");
#define DB Double #define LL long typedef long Long ll;
const int inf=0x3f3f3f3f;
Const LL LINF=0X3F3F3F3F3F3F3F3FLL;
const int dx[]={-1,0,1,0,1,-1,-1,1};
const int dy[]={0,1,0,-1,-1,1,-1,1};
const int MAXN=1E3+10;
const INT maxx=1<<17;
const double eps=1e-8;
const double eps=1e-8;
const int mod=1e9+7; Template<class t>inline t min (t a,t b,t c) {return min (min (a,b), c);} Template<class t>inline T max (t a,t b,t c) {return Max (max (a,b), c);} template<class t>inline t min (t a,t b,t c,t D) {return min (min (a,b), Min (c,d));} Templ Ate<class t>inline t max (t a,t b,t c,t D) {return Max (max (a,b), Max (c,d));} template <class t> inline bool SCA N_d (T &ret) {char c;int sgn;if (c = GetChar (), C = EOF) {return 0;} while (C!= '-' && (C < ' 0 ' | | C > ' 9 ')) {c = GetChar ();} SGN = (c = = '-')? -1:1;ret = (c = = '-')?
0: (C-' 0 '); while (c = GetChar (), C >= ' 0 ' && C <= ' 9 ') {ret = reT * + (C-' 0 ');}

RET *= Sgn;return 1;} inline bool Scan_lf (double &num) {char in;double dec=0.1;bool isn=false,isd=false;in=getchar (); if (in==eof) return
False while (in!= '-' &&in!= '. ') && (in< ' 0 ' | | In> ' 9]) In=getchar (); if (in== '-') {isn=true;num=0;} else if (in== '. ')
{isd=true;num=0;} else num=in-' 0 '; if (! IsD) {while (In=getchar (), in>= ' 0 ' &&in<= ' 9 ') {num*=10;num+=in-' 0 ';}} if (in!= '. ') {if (IsN) Num=-num;return true;} Else{while (In=getchar (), in>= ' 0 ' &&in<= ' 9 ') {num+=dec* (in-' 0 ');D ec*=0.1;}} if (IsN) Num=-num;return

true;} void out (LL a) {if (a < 0) {Putchar ('-'); a =-A;}
if (a >=) out (A/10);p Utchar (a% 10 + ' 0 ');}
void print (LL a) {out (a), puts ("");}
Freopen ("In.txt", "R", stdin);
Freopen ("Data.txt", "w", stdout);

Cerr << "Run time is" << clock () << Endl;
 typedef Complex<long double>complex;
 * * for FFT and IFFT before the reverse switch. * Position I and (i binary inverse position) interchange * Len must go to 2 power/void reverse (Complex y[],int len) {int i,j,K
        for (i = 1, j = len/2;i < len-1 i++) {if (I < j) Swap (y[i],y[j));
        Swap the elements of each other for a small reversal, i<j guarantee that the Exchange//i do normal +1,j left inversion type +1, always keep I and j are reversed k = LEN/2;
            while (J >= K) {J-= k;
        K/= 2;
    } if (J < k) J = k;
    }/* * do FFT * len must be 2^k form, * on==1 when dft,on==-1 is idft/void FFT (Complex a[],int n,int on) {reverse (a,n);
        for (int i=1;i<n;i<<=1) {Complex wn=complex (cos (pi/i), On*sin (pi/i));
            for (int j=0;j<n;j+= (i<<1)) {Complex W=complex (1,0);
                for (int k=0;k<i;k++,w=w*wn) {Complex x=a[j+k],y=w*a[j+k+i];
                A[j+k]=x+y;
            A[j+k+i]=x-y;
}} if (On==-1) for (int i=0;i<n;i++) a[i].real ()/=n; } struct Node {int c[maxx];}
A,b,c;
Complex A[maxx],b[maxx],c[maxx];
    int main () {int n,x;
       W (Scan_d (n)) { for (0,n,i) {scan_d (x);
            x+=20000;
            a.c[x]++;
            b.c[x+x]++;
        c.c[x+x+x]++;
        for (0,maxx,i) {a[i]=a.c[i],b[i]=b.c[i];
        FFT (a,maxx,1);
        FFT (b,maxx,1);
        for (0,maxx,i) {c[i]=a[i]* (a[i]*a[i]-3.0l*b[i]);
        FFT (c,maxx,-1);
            for (0,maxx,i) {ll ans= ((LL) (C[i].real () +0.5) +2*c.c[i])/6;
        if (ans>0) printf ("%d:%lld\n", I-60000,ans);
 }
    }
}




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.