Submission #10030228
Source Code Expand
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
template <int MODULUS = 1000000007>
struct modulo_int {
private:
long long value;
constexpr void normalize() {
value %= MODULUS;
if (value < 0) value += MODULUS;
}
public:
constexpr modulo_int(const long long& value_ = 0) : value(value_) { normalize(); }
constexpr modulo_int operator - () const { return modulo_int(MODULUS - value); }
constexpr modulo_int operator ~ () const { return power(MODULUS - 2); }
constexpr long long operator () () const { return value; }
constexpr modulo_int operator + (const modulo_int& rhs) const { return modulo_int(*this) += rhs; }
constexpr modulo_int& operator += (const modulo_int& rhs) {
if ((value += rhs.value) >= MODULUS) value -= MODULUS;
return (*this);
}
constexpr modulo_int operator - (const modulo_int& rhs) const { return modulo_int(*this) -= rhs; }
constexpr modulo_int& operator -= (const modulo_int& rhs) {
if ((value += MODULUS - rhs.value) >= MODULUS) value -= MODULUS;
return (*this);
}
constexpr modulo_int operator * (const modulo_int& rhs) const { return modulo_int(*this) *= rhs; }
constexpr modulo_int& operator *= (const modulo_int& rhs) {
(value *= rhs.value) %= MODULUS;
return (*this);
}
constexpr modulo_int operator / (const modulo_int& rhs) const { return modulo_int(*this) /= rhs; }
constexpr modulo_int& operator /= (const modulo_int& rhs) {
return (*this) *= ~rhs;
}
constexpr modulo_int power(const long long& power_) const {
modulo_int result(1), mult(*this);
for (long long t = power_; t > 0; t >>= 1) {
if (t & 1) result *= mult;
mult *= mult;
}
return result;
}
friend std::istream& operator >> (std::istream& stream, modulo_int& lhs) {
stream >> lhs.value;
lhs.normalize();
return stream;
}
friend std::ostream& operator << (std::ostream& stream, const modulo_int& rhs) {
return stream << rhs.value;
}
};
template <class T, int MODULUS = 998244353, int PRIM = 3>
void modulo_transform(std::vector<modulo_int<MODULUS>>& F, const bool& inverse = false) {
int F_sz = F.size();
for (int i = 0, j = 1; j < F_sz - 1; ++j) {
for (int k = (F_sz >> 1); k > (i ^= k); k >>= 1);
if (i < j) std::swap(F[i], F[j]);
}
modulo_int<MODULUS> zeta = modulo_int<MODULUS>(PRIM).power((MODULUS - 1) / F_sz);
if (inverse) zeta = ~zeta;
std::vector<modulo_int<MODULUS>> coeff(F_sz);
coeff[0] = 1;
for (int i = 1; i < F_sz; ++i) {
coeff[i] = coeff[i - 1] * zeta;
}
int index;
modulo_int<MODULUS> first, second;
for (int len = 1, bit = (F_sz >> 1); len < F_sz; len <<= 1, bit >>= 1) {
for (int k = 0; k < F_sz; k += (len << 1)) {
index = 0;
for (int i = 0; i < len; ++i) {
first = F[i + k];
second = F[(i + k) ^ len];
F[i + k] = coeff[0] * first + coeff[index] * second;
F[(i + k) ^ len] = coeff[0] * first + coeff[index + (F_sz >> 1)] * second;
index += bit;
}
}
}
}
template <class T, int MODULUS = 998244353, int PRIM = 3>
std::vector<T> convolute(const std::vector<T>& A, const std::vector<T>& B) {
int A_sz = A.size(), B_sz = B.size(), result_sz = A_sz + B_sz - 1;
int X_sz = 1;
while (X_sz < result_sz) {
X_sz <<= 1;
}
std::vector<modulo_int<MODULUS>> C(X_sz), D(X_sz);
for (int i = 0; i < A_sz; ++i) {
C[i] = A[i];
}
for (int i = 0; i < B_sz; ++i) {
D[i] = B[i];
}
modulo_transform<T, MODULUS, PRIM>(C);
modulo_transform<T, MODULUS, PRIM>(D);
for (int i = 0; i < X_sz; ++i) {
C[i] *= D[i];
}
modulo_transform<T, MODULUS, PRIM>(C, true);
modulo_int<MODULUS> sz_inv = ~modulo_int<MODULUS>(X_sz);
std::vector<T> result(result_sz);
for (int i = 0; i < result_sz; ++i) {
result[i] = static_cast<T>((C[i] * sz_inv)());
}
return result;
}
inline void rd(int &x) {
int c;
while ((c = getchar_unlocked() - '0') >= 0) {
x = x * 10 + c;
}
}
char out[15];
inline void pt(int x) {
int d = 0;
if (x == 0) {
out[d] = '0';
++d;
}
for (; x > 0; ++d) {
out[d] = (x % 10) + '0';
x /= 10;
}
while (d--) {
putchar_unlocked(out[d]);
}
putchar_unlocked('\n');
}
int main() {
int N;
rd(N);
std::vector<int> A(N), B(N);
for (int i = 0; i < N; ++i) {
rd(A[i]); rd(B[i]);
}
std::vector<int> answer = convolute<int, 998244353, 3>(A, B);
pt(0);
for (int i = 0; i < N + N - 1; ++i) {
pt(answer[i]);
}
}
Submission Info
Submission Time |
|
Task |
C - 高速フーリエ変換 |
User |
KoD |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
4947 Byte |
Status |
RE |
Exec Time |
5280 ms |
Memory |
328320 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 100 |
Status |
|
|
Set Name |
Test Cases |
Sample |
00_sample_01 |
All |
00_sample_01, 01_00_01, 01_01_19, 01_02_31, 01_03_22, 01_04_31, 01_05_40, 01_06_15, 01_07_39, 01_08_28, 01_09_30, 01_10_23, 01_11_33, 01_12_11, 01_13_28, 01_14_41, 01_15_26, 01_16_49, 01_17_34, 01_18_02, 01_19_33, 01_20_29, 02_00_51254, 02_01_82431, 02_02_17056, 02_03_34866, 02_04_6779, 02_05_65534, 02_06_65535, 02_07_65536, 02_08_65537, 02_09_65538, 02_10_100000 |
Case Name |
Status |
Exec Time |
Memory |
00_sample_01 |
TLE |
5256 ms |
328320 KB |
01_00_01 |
TLE |
5256 ms |
328320 KB |
01_01_19 |
TLE |
5280 ms |
-913664 KB |
01_02_31 |
TLE |
5279 ms |
-913664 KB |
01_03_22 |
TLE |
5275 ms |
-913664 KB |
01_04_31 |
TLE |
5275 ms |
-913664 KB |
01_05_40 |
TLE |
5275 ms |
-913664 KB |
01_06_15 |
TLE |
5275 ms |
-913664 KB |
01_07_39 |
TLE |
5275 ms |
-913664 KB |
01_08_28 |
TLE |
5275 ms |
-913664 KB |
01_09_30 |
TLE |
5275 ms |
-913664 KB |
01_10_23 |
TLE |
5275 ms |
-913664 KB |
01_11_33 |
TLE |
5275 ms |
-913664 KB |
01_12_11 |
TLE |
5275 ms |
-913664 KB |
01_13_28 |
TLE |
5275 ms |
-913664 KB |
01_14_41 |
TLE |
5274 ms |
-913664 KB |
01_15_26 |
TLE |
5275 ms |
-913664 KB |
01_16_49 |
TLE |
5275 ms |
-913664 KB |
01_17_34 |
TLE |
5274 ms |
-913664 KB |
01_18_02 |
TLE |
5257 ms |
328320 KB |
01_19_33 |
TLE |
5274 ms |
-913664 KB |
01_20_29 |
TLE |
5274 ms |
-913664 KB |
02_00_51254 |
RE |
302 ms |
384 KB |
02_01_82431 |
RE |
96 ms |
256 KB |
02_02_17056 |
RE |
95 ms |
256 KB |
02_03_34866 |
RE |
95 ms |
256 KB |
02_04_6779 |
RE |
95 ms |
256 KB |
02_05_65534 |
RE |
96 ms |
256 KB |
02_06_65535 |
RE |
96 ms |
256 KB |
02_07_65536 |
RE |
95 ms |
256 KB |
02_08_65537 |
RE |
96 ms |
256 KB |
02_09_65538 |
RE |
96 ms |
256 KB |
02_10_100000 |
RE |
96 ms |
256 KB |