QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#347765 | #8329. Excuse | ucup-team052# | AC ✓ | 592ms | 17484kb | C++23 | 2.8kb | 2024-03-09 15:18:28 | 2024-03-09 15:18:31 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int md = 998244353;
inline int add(int x, int y) {
if (x + y >= md) return x + y - md;
return x + y;
}
inline int sub(int x, int y) {
if (x < y) return x - y + md;
return x - y;
}
inline int mul(int x, int y) {
return 1ull * x * y % md;
}
inline int fpow(int x, int y) {
int ans = 1;
while (y) {
if (y & 1) ans = mul(ans, x);
y >>= 1; x = mul(x, x);
}
return ans;
}
namespace Poly {
vector <int> roots, rev;
void getRevRoot(int base) {
int n = 1 << base;
if ((int)rev.size() == n) return;
rev.resize(n); roots.resize(n);
for (int i = 1; i < n; i++) rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (base - 1));
for (int mid = 1; mid < n; mid <<= 1) {
int wn = fpow(3, (md - 1) / (mid << 1));
roots[mid] = 1;
for (int i = 1; i < mid; i++) roots[mid + i] = mul(roots[mid + i - 1], wn);
}
}
void ntt(vector <int> &a, int base) {
int n = 1 << base;
for (int i = 1; i < n; i++) {
if (i < rev[i]) {
swap(a[i], a[rev[i]]);
}
}
for (int mid = 1; mid < n; mid <<= 1) {
for (int i = 0; i < n; i += (mid << 1)) {
for (int j = 0; j < mid; j++) {
int x = a[i + j], y = mul(a[i + j + mid], roots[mid + j]);
a[i + j] = add(x, y); a[i + j + mid] = sub(x, y);
}
}
}
}
vector <int> operator * (vector <int> a, vector <int> b) {
int n = (int)a.size() + (int)b.size() - 1, base = 0;
while ((1 << base) < n) ++base;
a.resize(1 << base); b.resize(1 << base);
getRevRoot(base); ntt(a, base); ntt(b, base);
for (int i = 0; i < (1 << base); i++) a[i] = mul(a[i], b[i]);
ntt(a, base); reverse(a.begin() + 1, a.end());
int inv = fpow(1 << base, md - 2);
for (int i = 0; i < n; i++) a[i] = mul(a[i], inv);
a.resize(n);
return a;
}
vector <int> operator + (vector <int> a, vector <int> b) {
if (a.size() < b.size()) a.resize(b.size());
for (int i = 0; i < (int)b.size(); i++) a[i] = add(a[i], b[i]);
return a;
}
}
using Poly::operator *;
using Poly::operator +;
const int N = 1e5 + 5;
vector <int> f, g;
int fac[N], inv[N], pw[N];
int n;
int main() {
fac[0] = inv[0] = 1;
for (int i = 1; i < N; i++) {
fac[i] = mul(fac[i - 1], i);
inv[i] = fpow(fac[i], md - 2);
}
scanf("%d", &n);
f.resize(n + 1); g.resize(n + 1);
for (int i = 0; i <= n; i++) f[i] = g[i] = mul(fpow((md + 1) / 2, i), inv[i]);
f[0] = 0; g = f * g;
for (int base = 0; (1 << base) < n; base++) {
vector <int> F = f, G = g;
pw[0] = 1;
int qwq = fpow((md + 1) / 2, 1 << base);
for (int i = 0; i <= n; i++) {
if (i) pw[i] = mul(pw[i - 1], qwq);
F[i] = mul(F[i], pw[i]);
G[i] = mul(G[i], pw[i]);
}
g = g + f * G;
f = f * F;
f.resize(n + 1); g.resize(n + 1);
}
printf("%d\n", mul(g[n], fac[n]));
return 0;
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 12ms
memory: 4684kb
input:
1
output:
499122177
result:
ok 1 number(s): "499122177"
Test #2:
score: 0
Accepted
time: 9ms
memory: 4652kb
input:
3
output:
561512450
result:
ok 1 number(s): "561512450"
Test #3:
score: 0
Accepted
time: 12ms
memory: 4640kb
input:
10
output:
609769250
result:
ok 1 number(s): "609769250"
Test #4:
score: 0
Accepted
time: 10ms
memory: 4708kb
input:
1000
output:
475714976
result:
ok 1 number(s): "475714976"
Test #5:
score: 0
Accepted
time: 15ms
memory: 5036kb
input:
1024
output:
178624793
result:
ok 1 number(s): "178624793"
Test #6:
score: 0
Accepted
time: 592ms
memory: 17428kb
input:
100000
output:
537516197
result:
ok 1 number(s): "537516197"
Test #7:
score: 0
Accepted
time: 583ms
memory: 17472kb
input:
99471
output:
489775976
result:
ok 1 number(s): "489775976"
Test #8:
score: 0
Accepted
time: 529ms
memory: 12172kb
input:
65536
output:
171446457
result:
ok 1 number(s): "171446457"
Test #9:
score: 0
Accepted
time: 567ms
memory: 13004kb
input:
84792
output:
371578800
result:
ok 1 number(s): "371578800"
Test #10:
score: 0
Accepted
time: 582ms
memory: 17484kb
input:
93846
output:
841905002
result:
ok 1 number(s): "841905002"
Extra Test:
score: 0
Extra Test Passed