QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#203366 | #5478. Quiz Contest | complexor | WA | 0ms | 30292kb | C++14 | 3.3kb | 2023-10-06 16:57:04 | 2023-10-06 16:57:05 |
Judging History
answer
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <cassert>
#include <cmath>
#include <list>
typedef long long LL;
typedef long double LD;
typedef std::pair<int, int> pii;
typedef std::list<int>::iterator IT;
#define MP std::make_pair
#define fi first
#define se second
#define clr(f, n) memset(f, 0, n << 2)
#define cpy(f, g, n) memcpy(f, g, n << 2)
int read()
{
int s = 0, f = 1;
char c = getchar();
while (!(c >= '0' && c <= '9'))
f ^= c == '-', c = getchar();
while (c >= '0' && c <= '9')
s = s * 10 + (c - '0'), c = getchar();
return f ? s : -s;
}
const int MAXN = 200005, MOD = 998244353, G = 3, invG = (MOD + 1) / G;
auto fplus = [](int x, int y){ return x + y >= MOD ? x + y - MOD : x + y; };
auto fminus = [](int x, int y){ return x >= y ? x - y : x + MOD - y; };
auto Fplus = [](int &x, int y){ return x = fplus(x, y); };
auto Fminus = [](int &x, int y){ return x = fminus(x, y); };
int fpow(int x, int y = MOD - 2)
{
int res = 1;
for (; y; y >>= 1, x = (LL)x * x % MOD)
if (y & 1) res = (LL)res * x % MOD;
return res;
}
int n, m, a[MAXN], b[MAXN];
namespace Poly
{
int tr[MAXN << 2], lst = 0, f[MAXN << 2], g[MAXN << 2];
void set_tr(int n)
{
if (lst == n) return ;
n = lst;
for (int i = 1; i < n; i++)
tr[i] = (tr[i >> 1] << 1) | ((i & 1) ? (n >> 1) : 0);
}
void fmult(int a[], int b[], int n)
{
for (int i = 0; i < n; i++)
a[i] = (LL)a[i] * b[i] % MOD;
}
void NTT(int g[], int n, bool flg)
{
static int f[MAXN << 2], pw[MAXN << 2];
set_tr(n), pw[0] = 1;
for (int i = 0; i < n; i++) g[i] = f[tr[i]];
for (int l = 1; l < n; l <<= 1)
{
int tG = fpow(flg ? invG : G, (MOD - 1) / (l + l));
for (int i = 0; i < l; i++) pw[i] = (LL)tG * pw[i - 1] % MOD;
for (int s = 0; s < n; s += l + l)
for (int p = 0; p < l; p++)
{
int x = f[s | p], y = (LL)pw[p] * f[s | p | l] % MOD;
f[s | p] = fplus(x, y), f[s | p | l] = fminus(x, y);
}
}
if (flg)
{
int invn = fpow(n);
for (int i = 0; i < n; i++)
g[i] = (LL)f[i] * invn % MOD;
}
else cpy(g, f, n);
}
void times(int a[], int n, int b[], int m, int lim)
{
int len;
for (len = 1; len <= n + m; len <<= 1) ;
clr(f, len), clr(g, len);
cpy(f, a, n + 1), cpy(g, b, m + 1);
NTT(f, len, 0), NTT(g, len, 0);
fmult(f, g, len), NTT(f, len, 1);
cpy(a, f, len), clr(a + lim, len - lim);
}
}
std::vector<int> f[MAXN << 2];
int len[MAXN << 2], fac[MAXN], ifac[MAXN], inv[MAXN];
#define ls (x << 1)
#define rs (x << 1 | 1)
void maintain(int x)
{
len[x] = len[ls] + len[rs];
}
void build(int x, int l, int r)
{
if (l == r)
{
f[x].resize((len[x] = b[l] - 1) + 1);
for (int i = 0; i < b[l]; i++)
f[x][i] = (LL)ifac[i] * ifac[b[l] - i] % MOD;
return ;
}
int mid = (l + r) >> 1;
build(ls, l, mid), build(rs, mid + 1, r);
maintain(x);
}
int main()
{
n = read(), m = read();
for (int i = 1; i <= n; i++) a[i] = read();
for (int i = 1; i <= n; i++) b[i] = read();
inv[1] = 1;
for (int i = 2; i <= m; i++)
inv[i] = MOD - (LL)MOD / i * inv[MOD % i] % MOD;
fac[0] = ifac[0] = 1;
for (int i = 1; i <= m; i++)
{
fac[i] = (LL)fac[i - 1] * i % MOD;
ifac[i] = (LL)ifac[i - 1] * inv[i] % MOD;
}
build(1, 1, n);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 30292kb
input:
2 4 2 2 1 2
output:
result:
wrong answer 1st lines differ - expected: '20', found: ''