QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#210819 | #5478. Quiz Contest | Galex | WA | 4ms | 34940kb | C++14 | 3.4kb | 2023-10-11 20:24:51 | 2023-10-11 20:24:51 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
int read() {
int s = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9')
f = (ch == '-' ? -1 : 1), ch = getchar();
while (ch >= '0' && ch <= '9')
s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
return s * f;
}
const int mod = 998244353;
int qpow(int a, int b) {
int res = 1;
while (b) {
if (b & 1)
res = res * a % mod;
a = a * a % mod, b >>= 1;
}
return res;
}
#define poly vector<int>
namespace Poly {
const int g = 3, invg = 332748118;
vector<int> rev;
void NTT(vector<int> &a, int tp) {
int n = a.size();
for (int i = 0; i < n; i++)
if (i < rev[i])
swap(a[i], a[rev[i]]);
for (int j = 2; j <= n; j <<= 1) {
int ur = qpow(tp == 1 ? g : invg, (mod - 1) / j);
for (int i = 0; i < n; i += j)
for (int k = 0, w = 1; k < (j >> 1); k++, w = w * ur % mod) {
int x = a[i + k], y = a[i + k + (j >> 1)];
a[i + k] = (x + w * y) % mod, a[i + k + (j >> 1)] = (x - w * y % mod + mod) % mod;
}
}
if (tp == -1) {
int invn = qpow(n, mod - 2);
for (int i = 0; i < n; i++)
a[i] = a[i] * invn % mod;
}
}
void init(vector<int> &a, vector<int> &b) {
int n = a.size(), m = b.size(), N = 1, pw = 0;
while (N < n + m)
N <<= 1, pw++;
a.resize(N), b.resize(N), rev.resize(N);
for (int i = 0; i < N; i++)
rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (pw - 1));
}
vector<int> mul(vector<int> a, vector<int> b) {
int n = a.size(), m = b.size();
init(a, b), NTT(a, 1), NTT(b, 1);
int len = a.size();
for (int i = 0; i < len; i++)
a[i] = a[i] * b[i] % mod;
NTT(a, -1), a.resize(n + m - 1);
return a;
}
vector<int> minusmul(vector<int> a, vector<int> b) {
int n = a.size(), m = b.size();
reverse(b.begin(), b.end());
a = mul(a, b);
for (int i = 0; i < n; i++)
a[i] = a[i + m - 1];
a.resize(n);
return a;
}
}
#define N 200005
int n, m;
int a[N], b[N];
int fac[N], inv[N];
void init(int n) {
fac[0] = 1;
for (int i = 1; i <= n; i++)
fac[i] = fac[i - 1] * i % mod;
inv[n] = qpow(fac[n], mod - 2);
for (int i = n; i; i--)
inv[i - 1] = inv[i] * i % mod;
}
int ans[N];
#define ls (p << 1)
#define rs (p << 1 | 1)
#define mid ((l + r) >> 1)
poly f[N], g[N << 2];
void init(int l, int r, int p) {
if (l == r) {
g[p] = f[l];
return ;
}
init(l, mid, ls), init(mid + 1, r, rs);
g[p] = Poly::mul(g[ls], g[rs]);
}
poly calc(poly x, poly y) {
poly res = Poly::minusmul(x, y);
res.resize((int)x.size() - (int)y.size());
return res;
}
void solve(int l, int r, int p, poly sum) {
if (l == r) {
ans[l] = sum[b[l]] * inv[b[l] - 1] % mod * inv[a[l] - b[l]] % mod;
return ;
}
solve(l, mid, ls, calc(sum, g[rs]));
solve(mid + 1, r, rs, calc(sum, g[ls]));
}
signed 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();
init(200000);
for (int i = 1; i <= n; i++) {
f[i].resize(b[i]);
for (int j = 0; j < b[i]; j++)
f[i][j] = inv[j] * inv[a[i] - j] % mod;
}
init(1, n, 1);
poly st(m - n + 2);
for (int i = 1; i <= m - n + 1; i++)
st[i] = fac[i - 1] * fac[m - i] % mod;
solve(1, n, 1, st);
int val = 1;
for (int i = 1; i <= n; i++)
val = val * fac[a[i]] % mod;
for (int i = 1; i <= n; i++)
printf("%lld\n", ans[i] * val % mod);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 33756kb
input:
2 4 2 2 1 2
output:
20 4
result:
ok 2 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 33360kb
input:
4 6 1 1 2 2 1 1 1 2
output:
168 168 336 48
result:
ok 4 lines
Test #3:
score: 0
Accepted
time: 0ms
memory: 34588kb
input:
4 82 20 22 12 28 20 22 7 8
output:
746371221 528486621 148054814 913602744
result:
ok 4 lines
Test #4:
score: 0
Accepted
time: 0ms
memory: 34940kb
input:
2 2 1 1 1 1
output:
1 1
result:
ok 2 lines
Test #5:
score: 0
Accepted
time: 3ms
memory: 34912kb
input:
1 1 1 1
output:
1
result:
ok single line: '1'
Test #6:
score: 0
Accepted
time: 0ms
memory: 33892kb
input:
1 2 2 1
output:
2
result:
ok single line: '2'
Test #7:
score: 0
Accepted
time: 0ms
memory: 33324kb
input:
2 5 2 3 2 1
output:
12 108
result:
ok 2 lines
Test #8:
score: -100
Wrong Answer
time: 4ms
memory: 34852kb
input:
3 6 3 1 2 3 1 2
output:
0 312 192
result:
wrong answer 1st lines differ - expected: '108', found: '0'