提交记录 6462


用户 题目 状态 得分 用时 内存 语言 代码长度
WAAutoMaton 1002i. 【模板题】多项式乘法 Accepted 100 36.454 ms 128496 KB C++11 4.20 KB
提交时间 评测时间
2018-10-15 19:25:17 2020-08-01 00:44:36
/*+lmake
 * DEFINE += MDEBUG
 * STD = c++11
 */
#include <stdio.h>
#include <math.h>
#include <algorithm>
#ifdef MDEBUG
#define debug(args...)                                                                             \
    {                                                                                              \
        dbg, args;                                                                                 \
        cerr << endl;                                                                              \
    }
#define massert(x) assert(x)
#else
#define debug(args...) // Just strip off all debug tokens
#define massert(x)
#endif
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
void iopen()
{
    static bool isOpen = false;
    if (!isOpen) {
        isOpen = true;
#ifdef MDEBUG
        freopen("in.txt", "r", stdin);
#endif
    }
}
template <size_t _I_Buffer_Size = 1 << 23, size_t _O_Buffer_Size = 1 << 23>
struct IO_Tp
{
    char _I_Buffer[_I_Buffer_Size];
    char *_I_pos;

    char _O_Buffer[_O_Buffer_Size];
    char *_O_pos;

    IO_Tp()
        : _I_pos(_I_Buffer)
        , _O_pos(_O_Buffer)
    {
        iopen();
        fread(_I_Buffer, 1, _I_Buffer_Size, stdin);
    }

    ~IO_Tp() { fwrite(_O_Buffer, 1, _O_pos - _O_Buffer, stdout); }

    inline bool is_digit(const char ch) { return '0' <= ch && ch <= '9'; }

    template <typename Int>
    inline IO_Tp &operator>>(Int &res)
    {
        res = 0;
        int k = 1;
        while (!is_digit(*_I_pos)) {
            if (*_I_pos == '-')
                k = -1;
            _I_pos++;
        }
        do
            (res *= 10) += (*_I_pos++) & 15;
        while (is_digit(*_I_pos));
        res *= k;
        return *this;
    }

    inline char getop()
    {
        while (!is_digit(*_I_pos))
            _I_pos++;
        return (*_I_pos++) & 15;
    }

    template <typename Int>
    inline IO_Tp &operator<<(Int n)
    {
        if (n < 0) {
            *_O_pos++ = '-';
            n = -n;
        }
        static char _buf[20];
        char *_pos(_buf);
        do
            *_pos++ = '0' + n % 10;
        while (n /= 10);
        while (_pos != _buf)
            *_O_pos++ = *--_pos;
        return *this;
    }

    inline IO_Tp &operator<<(char ch)
    {
        *_O_pos++ = ch;
        return *this;
    }
};
IO_Tp<1 << 25, 1 << 25> IO;

#define MAXN 4000000
template <typename Double>
struct Complex
{
    Double r, i;
    Complex(Double r = 0, Double i = 0)
        : r(r)
        , i(i)
    {
    }
    inline Double real() { return r; }
    inline Double imag() { return i; }
};
using complex_t = Complex<double>;
complex_t operator+(const complex_t &a, const complex_t &b)
{
    return { a.r + b.r, a.i + b.i };
}
complex_t operator-(const complex_t &a, const complex_t &b)
{
    return { a.r - b.r, a.i - b.i };
}
complex_t operator*(const complex_t &a, const complex_t &b)
{
    return { a.r * b.r - a.i * b.i, a.r * b.i + a.i * b.r };
}
complex_t a[MAXN + 10], b[MAXN + 10];
int rev[MAXN + 10];
const double pi = acos(-1);
void fft(int n, complex_t *a, int flag)
{
    for (int i = 0, j = 0; i < n; ++i) {
        if (i > j)
            swap(a[i], a[j]);
        for (int k = n >> 1; (j ^= k) < k; k >>= 1)
            ;
    }
    for (int i = 1; i < n; i *= 2) {
        int nn = i * 2;
        complex_t wn = (complex_t){ cos(2 * pi / nn), flag * sin(2 * pi / nn) };
        for (int j = 0; j < n; j += nn) {
            complex_t *a1 = a + j, *a2 = a1 + i;
            complex_t w = (complex_t){ 1, 0 };
            for (int k = 0; k < i; ++k) {
                complex_t x = a1[k], y = w * a2[k];
                a1[k] = x + y;
                a2[k] = x - y;
                w = w * wn;
            }
        }
    }
}
int main()
{
    iopen();
    int n, m;
    IO >> n >> m;
    for (int i = 0; i <= n; ++i) {
        int t;
        IO >> t;
        a[i] = complex_t(t, 0);
    }
    for (int i = 0; i <= m; ++i) {
        int t;
        IO >> t;
		a[i].i=t;
    }
    LL l = 1;
    for (; l <= n + m; l *= 2)
        ;
    fft(l, a, 1);
    for (int i = 0; i <= l; ++i) {
        a[i] = a[i] * a[i];
    }
    fft(l, a, -1);
    for (int i = 0; i <= n + m; ++i) {
        IO << LL((a[i].imag() / (2*l)) + 0.5) << ' ';
    }
    IO << '\n';
    return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #114.388 ms122 MB + 108 KBAcceptedScore: 0

Subtask #1 Testcase #236.28 ms125 MB + 336 KBAcceptedScore: 100

Subtask #1 Testcase #323.417 ms122 MB + 864 KBAcceptedScore: 0

Subtask #1 Testcase #423.461 ms122 MB + 844 KBAcceptedScore: 0

Subtask #1 Testcase #514.183 ms122 MB + 108 KBAcceptedScore: 0

Subtask #1 Testcase #613.654 ms122 MB + 108 KBAcceptedScore: 0

Subtask #1 Testcase #713.871 ms122 MB + 108 KBAcceptedScore: 0

Subtask #1 Testcase #835.458 ms124 MB + 756 KBAcceptedScore: 0

Subtask #1 Testcase #935.462 ms124 MB + 756 KBAcceptedScore: 0

Subtask #1 Testcase #1034.93 ms124 MB + 148 KBAcceptedScore: 0

Subtask #1 Testcase #1136.454 ms125 MB + 496 KBAcceptedScore: 0

Subtask #1 Testcase #1233.267 ms123 MB + 256 KBAcceptedScore: 0

Subtask #1 Testcase #1314.385 ms122 MB + 108 KBAcceptedScore: 0


Judge Duck Online | 评测鸭在线
Server Time: 2024-04-25 23:07:18 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用