QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#4027#495. 特征多项式Qingyu0 0ms0kbC++2.8kb2020-05-11 13:58:332022-01-17 12:43:13

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-01-17 12:43:13]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2020-05-11 13:58:33]
  • 提交

answer

#include <bits/stdc++.h>
 
typedef long double ld;
const int N = 1e6 + 50;
const int M = 2e5 + 50;
const ld pi = acos(-1.0);
 
int n, m, k, len, rev[N];
int yy[N], B[N];
struct Complex
{
    ld x, y;
    Complex(ld x = 0.0, ld y = 0.0) : x(x), y(y) {}
} A[N], omega[N], omegaInv[N];
 
inline Complex operator+ (const Complex &a, const Complex &b) { return Complex(a.x + b.x, a.y + b.y); }
inline Complex operator- (const Complex &a, const Complex &b) { return Complex(a.x - b.x, a.y - b.y); }
inline 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); }
inline Complex operator/ (const Complex &a, const ld t) { return Complex(a.x / t, a.y / t); }
 
inline void NTTInit(int n)
{
    k = 0, len = 1;
    while (len <= n) ++k, len <<= 1;
    for (int i = 1; i < len; ++i) rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (k - 1));
    omega[0] = omegaInv[0] = 1;
    Complex t(cos(2 * pi / len), sin(2 * pi / len));
    for (int i = 1; i < len; ++i) omega[i] = omegaInv[len - i] = omega[i - 1] * t;
}
 
inline void NTT(Complex *A, const Complex *w)
{
    for (int i = 0; i < len; ++i) if (i < rev[i]) std::swap(A[i], A[rev[i]]);
    for (int h = 1; h < len; h <<= 1)
        for (int t = len / (h * 2), j = 0; j < len; j += h * 2)
        {
            const Complex *wn = w;
            for (int i = j; i < j + h; ++i)
            {
                const Complex _1 = A[i], _2 = A[i + h] * *wn;
                A[i] = _1 + _2, A[i + h] = _1 - _2;
                wn += t;
            }
        }
    if (w == omegaInv)
    {
        for (int i = 0; i < len; ++i) A[i] = A[i] / len;
    }
}
 
inline char nc()
{
    static char buf[1000000], *p1 = buf, *p2 = buf;
    return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++;
}
 
inline int read()
{
    int res = 0;
    char ch;
    do ch = nc(); while (ch < 48 || ch > 57);
    do res = res * 10 + ch - 48, ch = nc(); while (ch >= 48 && ch <= 57);
    return res;
}
 
 
inline void solve()
{
    n = read();
    memset(A, 0, sizeof A); memset(B, 0, sizeof B);
	memset(yy, 0, sizeof yy); 
    for (int i = 1; i <= n; ++i)
    {
        int t = read();
        ++yy[t];
        A[t].x = yy[t];
    }
    NTT(A, omega);
    for (int i = 0; i < len; ++i) A[i] = A[i] * A[i];
    NTT(A, omegaInv);
    long double ans = 0.0, sum = 0.0;
    for (int i = 0; i < len; ++i) B[i] = (A[i].x + 0.5);
    for (int i = 0; i * 2 < len; ++i) B[i * 2] -= yy[i];
    for (int i = 0; i < len; ++i) B[i] /= 2;
    for (int i = 0; i < len; ++i)
    {
        sum += B[i];
        ans += yy[i] * sum;
    }
    ans = 1 - ans / n / (n - 1) / (n - 2) * 2 * 3;
    printf("%.7Lf\n", ans); 
}
int main()
{
	NTTInit(M);
    int t = read();
    while (t--) solve();
}

详细

Subtask #1:

score: 0
Runtime Error

Test #1:

score: 0
Runtime Error

input:

50
266912498 835091017 452080669 685381424 269707314 292908762 277505221 781233421 510658789 799543577 844885899 736245256 651479261 844896506 567470542 729489183 865380130 158739155 271515176 36971482 560309217 933384827 499620370 303835488 898526954 987576590 241842859 41182893 341293849 605213418...

output:


result:


Subtask #2:

score: 0
Runtime Error

Test #11:

score: 0
Runtime Error

input:

500
912067299 560421914 613266377 676357217 299801919 277177164 278302771 810389156 943836886 639998245 855554810 784105751 403876660 750427762 374514286 219539473 45338811 881611774 125191025 37880987 91597910 672490636 695938784 118178926 898788752 890452808 971253057 929997223 751058722 706074011...

output:


result: