Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <bits/stdc++.h>
- using namespace std;
- const int MX = 3e6+8;
- typedef long double ld;
- typedef long long ll;
- typedef complex<ld> cplx;
- const ld Pi = acos(-1.0);
- void change(vector<cplx> &y) {
- int ln = y.size();
- for (int i = 1, j = ln >> 1; i < ln - 1; i++) {
- if (i < j)
- swap(y[i], y[j]);
- int k = ln >> 1;
- while (j >= k) {
- j -= k;
- k >>= 1;
- }
- j += k;
- }
- }
- void fft(vector<cplx> &y, int on) {
- change(y);
- int len = y.size();
- for (int m = 2; m <= len; m <<= 1) {
- cplx wm(cos(-on * 2 * Pi / m), sin(-on * 2 * Pi / m));
- for (int k = 0; k < len; k += m) {
- cplx w(1, 0);
- for (int j = 0; j < m / 2; j++) {
- cplx u = y[k + j];
- cplx t = w * y[k + j + m / 2];
- y[k + j] = u + t;
- y[k + j + m / 2] = u - t;
- w = w*wm;
- }
- }
- }
- if (on == -1)
- for (int i = 0; i < len; i++)
- y[i].real(y[i].real() / len);
- }
- void mult(vector<ll> a, vector<ll> b, vector<ll> &res) {
- int len = 1, la = a.size(), lb = b.size();
- while (len < la + lb)
- len <<= 1;
- vector<cplx> x1(len), x2(len);
- for (int i = 0; i < la; i++)
- x1[i] = cplx(a[i], 0);
- for (int i = la; i < len; i++)
- x1[i] = cplx(0, 0);
- for (int i = 0; i < lb; i++)
- x2[i] = cplx(b[i], 0);
- for (int i = lb; i < len; i++)
- x2[i] = cplx(0, 0);
- fft(x1, 1);
- fft(x2, 1);
- for (int i = 0; i < len; i++)
- x1[i] = x1[i] * x2[i];
- fft(x1, -1);
- res.resize(len);
- for (int i = 0; i < len; i++)
- res[i] = x1[i].real() + 0.5;
- }
- vector <long long> v,u,res;
- int main() {
- int n;
- cin>>n;
- v.resize(2000000);
- u.resize(2000000);
- for ( int i=0 ; i<n ; i++ )
- {
- long long x;
- cin>>x;
- v[x] = u[x] = 1;
- }
- mult( v , u , res );
- //for ( int i=0 ; i<2000000 ; i++ ) { cout<<res[i]<<" "; }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement