1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
| #include <bits/stdc++.h> #define L(i, j, k, l) for(int i = (j); i <= (k); i += (l)) #define R(i, j, k, l) for(int i = (j); i >= (k); i -= (l)) #define ll long long #define ld long double #define ull unsigned long long
using namespace std; const int N = 5e5 + 10; const ld PI = acos(-1); int a[N]; struct Complex { ld x, y; Complex(ld _x = 0, ld _y = 0) {x = _x, y = _y;} Complex operator+(Complex e) {return Complex(x + e.x, y + e.y);} Complex operator-(Complex e) {return Complex(x - e.x, y - e.y);} Complex operator*(Complex e) {return Complex(x * e.x - y * e.y, x * e.y + y * e.x);} } f[N], g[N]; int rev[N]; ll s1[N], s2[N], s3[N];
inline int read() { int x = 0, y = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') y = -1; c = getchar();} while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return x * y; }
inline void fft(Complex a[], int n, int flg) { L(i, 0, n - 1, 1) if (i < rev[i]) swap(a[i], a[rev[i]]); L(mid, 1, n - 1, mid) { Complex W(cos(PI / mid), sin(PI / mid) * flg); L(i, 0, n - 1, mid << 1) { Complex w(1, 0); L(j, i, i + mid - 1, 1) { Complex x = a[j], y = w * a[j + mid]; a[j] = x + y, a[j + mid] = x - y; w = w * W; } } } }
inline int FFT(int n, int m, Complex a[], Complex b[]) { int k = 1, l = 0; while (k <= n + m) k <<= 1, l++; L(i, 0, k - 1, 1) rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (l - 1)); fft(a, k, 1), fft(b, k, 1); L(i, 0, k - 1, 1) a[i] = a[i] * b[i]; fft(a, k, -1); return k; }
int main() { int n = read(), Max = 0; L(i, 1, n, 1) a[i] = read() + 20000, Max = max(Max, a[i]); L(i, 1, n, 1) f[a[i]].x++, g[a[i]].x++; int k = FFT(Max, Max, f, g); L(i, 0, 2 * Max, 1) f[i].x = (ld)(ll)(f[i].x / k + 0.5); L(i, 0, 3e5, 1) f[i].y = g[i].x = g[i].y = 0; L(i, 1, n, 1) g[a[i]].x++; k = FFT(2 * Max, Max, f, g); L(i, 0, 3 * Max, 1) s1[i] = (ll)(f[i].x / k + 0.5); L(i, 0, 3e5, 1) f[i].x = f[i].y = g[i].x = g[i].y = 0; L(i, 1, n, 1) f[2 * a[i]].x++, g[a[i]].x++; k = FFT(2 * Max, Max, f, g); L(i, 0, 3 * Max, 1) s2[i] = (ll)(f[i].x / k + 0.5); L(i, 1, n, 1) s3[3 * a[i]]++; L(i, 0, 3 * Max, 1) { ll res = (s1[i] - 3 * s2[i] + 2 * s3[i]) / 6; if (res) printf("%d : %lld\n", i - 60000, res); } return 0; }
|