QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#956972 | #10078. FS's Critical Concert | Gentle_fft | AC ✓ | 1145ms | 69804kb | C++20 | 6.7kb | 2025-03-30 01:45:35 | 2025-03-30 01:45:35 |
Judging History
answer
#define mod98 998'244'353LL
#define mod107 1'000'000'007LL
#define mod109 1'000'000'009LL
#define _CRT_SECURE_NO_WARNINGS
//#define HSE
//#define DE
#include <cstring>
#include <vector>
//#include <bits/stdc++.h>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <stack>
#include <ios>
#include <iostream>
#include <memory>
#include <string>
#include <queue>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <chrono>
#include <set>
#include <thread>
#include <random>
#include <fstream>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <numeric>
//#include <numbers>
#include <complex>
#include <type_traits>
#include <utility>
#include <climits>
//#define DEBUG
/*
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class c, class cmp = less<c> > using ordered_set = tree<c, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
*/
using namespace std;
using CLD = complex<double>;
using ll = long long;
#ifdef HSE
#include "optimization.h"
void yes(bool b) {
if (b) {
writeWord("Yes\n");
}
else {
writeWord("No\n");
}
}
#endif
#define forn(i, n) for (int i = 0; i < n; ++i)
#define all(a) a.begin(), a.end()
const double PI = acos(-1.0);
const ll mod = mod98;
const ll half_mod = 100'000ll;
namespace {
std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
template<typename T>
void relaxMax(T& old, const T& val) {
old = std::max(old, val);
}
template<typename T>
void relaxMin(T& old, const T& val) {
old = std::min(old, val);
}
#ifndef HSE
void yes(bool b) {
if (b) {
std::cout << "Yes\n";
}
else {
std::cout << "No\n";
}
}
#endif
template<typename T>
void zero(std::vector<T>& vec, T val = 0) {
for (auto& i : vec) i = val;
}
template<typename T>
void readvec(std::vector<T>& vec) {
forn(i, vec.size()) cin >> vec[i];
}
template<typename T1, typename T2 = T1, typename T3 = T2>
struct triple {
T1 first;
T2 second;
T3 third;
bool operator<(const triple& other) const {
if (first < other.first) return true;
if (first > other.first) return false;
if (second < other.second) return true;
if (second > other.second) return false;
if (third < other.third) return true;
return false;
}
};
template<typename T1, typename T2 = T1, typename T3 = T2>
inline std::istream& operator>>(std::istream& is, triple<T1, T2, T3>& a) {
is >> a.first >> a.second >> a.third;
return is;
}
int64_t gcd(int64_t a, int64_t b) {
if (b == 0) return a;
if (a == 0) return b;
return gcd(b, a % b);
}
int64_t deg(int64_t val, int d, const int64_t md = mod) {
int64_t ans = 1, mn = val;
while (d > 0) {
if (d & 1) ans *= mn, ans %= md;
mn *= mn, mn %= md, d >>= 1;
}
return ans;
}
}
vector<ll> roots;
void calc(int n) {
roots.resize(n);
for (int k = 1; k < n; k *= 2) {
roots[k] = 1;
ll mul = deg(3, (mod98-1)/(2*k));
for (int i = 1; i < k; ++i) roots[k + i] = roots[(k + i) / 2] * (i & 1 ? mul : 1) % mod;
}
}
void rev(int n, int d, vector<ll>& a) {
vector<int> inv(n);
forn(i, n) inv[i] = inv[i / 2] / 2 + ((i & 1) << (d - 1));
forn(i, n) if (inv[i] > i) swap(a[i], a[inv[i]]);
}
void fft(int n, int d, vector<ll>& a) {
rev(n, d, a);
for (int k = 1; k < n; k *= 2) {
for (int i = 0; i < n; i += 2 * k) {
forn(j, k) {
ll mul = roots[k + j] * a[i+j+k] % mod;
a[i + j + k] = (mod + a[i + j] - mul) % mod;
a[i + j] = (a[i + j] + mul) % mod;
}
}
}
}
void minus(vector<ll>& a) {
forn(i, a.size()) a[i] = (mod - a[i]) % mod;
}
vector<ll> multiplication(const vector<ll>& a, const vector<ll>& b, int len) {
int n = 1, z = 0;
while (n < len * 2) ++z, n *= 2;
vector<ll> c(n), d(n);
calc(n);
forn(i, min(len, (int)a.size())) c[i] = a[i] % mod;
forn(i, min(len, (int)b.size())) d[i] = b[i] % mod;
fft(n, z, c);
fft(n, z, d);
forn(i, n) c[i] = c[i] * d[i] % mod;
fft(n, z, c);
reverse(1 + all(c));
ll m = deg(n, mod - 2);
forn(i, n) c[i] = c[i] * m % mod;
c.resize(len);
return c;
}
vector<ll> rps(const vector<ll>& a) {
vector<ll> b(1), c;
b[0] = deg(a[0], mod - 2);
for (int k = 1; k < a.size(); k *= 2) {
c = multiplication(a, b, 2 * k);
::minus(c);
c[0] = (c[0] + 2) % mod;
b = multiplication(b, c, 2 * k);
}
b.resize(a.size());
return b;
}
vector<ll> fact, bfact, graph, con, ans;
void build_fact(int n) {
fact.resize(n), bfact.resize(n);
fact[0] = 1;
for (int i = 1; i < n; ++i) fact[i] = fact[i - 1] * i % mod;
bfact[n - 1] = deg(fact[n - 1], mod - 2);
for (int i = n - 2; i >= 0; --i) bfact[i] = bfact[i + 1] * (i + 1) % mod;
}
void calc_graph(int n) {
graph.resize(n);
forn(i, n) graph[i] = deg(2, 1ll * i * (i - 1) / 2 % (mod - 1));
graph[0] = 0;
}
void calc_con(int n) {
vector<ll> a1(n), a2(n);
forn(i, n) a1[i] = graph[i] * bfact[i] % mod * i % mod;
forn(i, n) a2[i] = graph[i] * bfact[i] % mod;
a2[0] = (a2[0] + 1) % mod;
con = multiplication(a1, rps(a2), n);
forn(i, n) if (i) con[i] = con[i] * fact[i - 1] % mod;
}
void calc_ans(int n) {
vector<ll> c = con, g = graph;
g.resize(n);
g[0] = 1;
forn(i, n) if(i) c[i] = c[i] * bfact[i-1] % mod;
forn(i, n) g[i] = g[i] * bfact[i] % mod;
c = multiplication(c, c, n);
c = multiplication(c, g, n);
ans = c;
ll m = deg(2, mod - 2);
forn(i, n) ans[i] = ans[i] * fact[i] %mod * m % mod;
}
template <typename T>
void print_vec(const vector<T>& a) {
for (auto i : a) cout << i << ' ';
cout << '\n';
}
void solve() {
int n;
cin >> n;
++n;
build_fact(n), calc_graph(n);
calc_con(n), calc_ans(n);
/*
print_vec(fact);
print_vec(bfact);
print_vec(graph);
print_vec(con);
print_vec(ans);*/
cout << ans[n - 1] << '\n';
}
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
int t = 1;
//cin >> t;
while (t--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3712kb
input:
3
output:
9
result:
ok 1 number(s): "9"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
8
output:
130981312
result:
ok 1 number(s): "130981312"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
1
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
2
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
4
output:
96
result:
ok 1 number(s): "96"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
5
output:
1500
result:
ok 1 number(s): "1500"
Test #7:
score: 0
Accepted
time: 1ms
memory: 3712kb
input:
6
output:
37560
result:
ok 1 number(s): "37560"
Test #8:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
7
output:
1626912
result:
ok 1 number(s): "1626912"
Test #9:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
9
output:
591945260
result:
ok 1 number(s): "591945260"
Test #10:
score: 0
Accepted
time: 1ms
memory: 3712kb
input:
10
output:
877137661
result:
ok 1 number(s): "877137661"
Test #11:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
11
output:
654711510
result:
ok 1 number(s): "654711510"
Test #12:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
12
output:
896890421
result:
ok 1 number(s): "896890421"
Test #13:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
13
output:
544152239
result:
ok 1 number(s): "544152239"
Test #14:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
14
output:
203161729
result:
ok 1 number(s): "203161729"
Test #15:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
15
output:
686403302
result:
ok 1 number(s): "686403302"
Test #16:
score: 0
Accepted
time: 1ms
memory: 3712kb
input:
16
output:
551788068
result:
ok 1 number(s): "551788068"
Test #17:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
17
output:
778761614
result:
ok 1 number(s): "778761614"
Test #18:
score: 0
Accepted
time: 1ms
memory: 3712kb
input:
18
output:
372704747
result:
ok 1 number(s): "372704747"
Test #19:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
19
output:
48091879
result:
ok 1 number(s): "48091879"
Test #20:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
20
output:
811962966
result:
ok 1 number(s): "811962966"
Test #21:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
21
output:
580925653
result:
ok 1 number(s): "580925653"
Test #22:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
22
output:
473369147
result:
ok 1 number(s): "473369147"
Test #23:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
23
output:
370850086
result:
ok 1 number(s): "370850086"
Test #24:
score: 0
Accepted
time: 1ms
memory: 3712kb
input:
24
output:
633052748
result:
ok 1 number(s): "633052748"
Test #25:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
25
output:
760181773
result:
ok 1 number(s): "760181773"
Test #26:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
26
output:
618049730
result:
ok 1 number(s): "618049730"
Test #27:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
27
output:
197289938
result:
ok 1 number(s): "197289938"
Test #28:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
28
output:
708240707
result:
ok 1 number(s): "708240707"
Test #29:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
29
output:
726463024
result:
ok 1 number(s): "726463024"
Test #30:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
30
output:
587550457
result:
ok 1 number(s): "587550457"
Test #31:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
100
output:
721970458
result:
ok 1 number(s): "721970458"
Test #32:
score: 0
Accepted
time: 4ms
memory: 4040kb
input:
2562
output:
947609016
result:
ok 1 number(s): "947609016"
Test #33:
score: 0
Accepted
time: 4ms
memory: 4076kb
input:
3410
output:
462244613
result:
ok 1 number(s): "462244613"
Test #34:
score: 0
Accepted
time: 11ms
memory: 4188kb
input:
5712
output:
225049703
result:
ok 1 number(s): "225049703"
Test #35:
score: 0
Accepted
time: 22ms
memory: 5208kb
input:
10002
output:
577290168
result:
ok 1 number(s): "577290168"
Test #36:
score: 0
Accepted
time: 94ms
memory: 10960kb
input:
50012
output:
513616100
result:
ok 1 number(s): "513616100"
Test #37:
score: 0
Accepted
time: 200ms
memory: 18384kb
input:
75162
output:
197336463
result:
ok 1 number(s): "197336463"
Test #38:
score: 0
Accepted
time: 210ms
memory: 20620kb
input:
129257
output:
307374532
result:
ok 1 number(s): "307374532"
Test #39:
score: 0
Accepted
time: 459ms
memory: 34788kb
input:
202572
output:
342782823
result:
ok 1 number(s): "342782823"
Test #40:
score: 0
Accepted
time: 1130ms
memory: 64632kb
input:
348252
output:
992752188
result:
ok 1 number(s): "992752188"
Test #41:
score: 0
Accepted
time: 1145ms
memory: 68132kb
input:
452632
output:
374752381
result:
ok 1 number(s): "374752381"
Test #42:
score: 0
Accepted
time: 1109ms
memory: 69804kb
input:
500000
output:
553811795
result:
ok 1 number(s): "553811795"