QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#359859 | #8010. Hierarchies of Judges | ucup-team1209 | AC ✓ | 920ms | 78808kb | C++20 | 5.5kb | 2024-03-20 22:10:17 | 2024-03-20 22:10:18 |
Judging History
answer
#include<bits/stdc++.h>
namespace my_std{
using namespace std;
#define pii pair<int,int>
#define fir first
#define sec second
#define MP make_pair
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define drep(i,x,y) for (int i=(x);i>=(y);i--)
#define go(x) for (int i=head[x];i;i=edge[i].nxt)
#define templ template<typename T>
#define mod 998244353ll
#define sz 202020
#define N sz<<2
typedef long long ll;
typedef unsigned long long u64;
typedef double db;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
templ inline T rnd(T l,T r) {return uniform_int_distribution<T>(l,r)(rng);}
templ inline bool chkmax(T &x,T y){return x<y?x=y,1:0;}
templ inline bool chkmin(T &x,T y){return x>y?x=y,1:0;}
templ inline void read(T& t) {
t=0;char f=0,ch=getchar();double d=0.1;
while(ch>'9'||ch<'0') f|=(ch=='-'),ch=getchar();
while(ch<='9'&&ch>='0') t=t*10+ch-48,ch=getchar();
if(ch=='.'){ch=getchar();while(ch<='9'&&ch>='0') t+=d*(ch^48),d*=0.1,ch=getchar();}
t=(f?-t:t);
}
template<typename T,typename... Args>inline void read(T& t,Args&... args){read(t); read(args...);}
void file() {
#ifdef zqj
freopen("a.in","r",stdin);
#endif
}
inline void chktime() {
#ifdef zqj
cerr<<clock()/1000.0<<'\n';
#endif
}
#ifdef mod
ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x%mod) if (y&1) ret=ret*x%mod;return ret;}
ll inv(ll x){return ksm(x,mod-2);}
#else
ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x) if (y&1) ret=ret*x;return ret;}
#endif
}
using namespace my_std;
ll fac[sz],_fac[sz],_inv[sz];
void _init(){_fac[0]=fac[0]=1;rep(i,1,sz-1) _fac[i]=inv(fac[i]=fac[i-1]*i%mod),_inv[i]=_fac[i]*fac[i-1]%mod;}
int rev[N], wn[N], lim, invlim;
int _pow(int a, int b, int ans = 1) {
for(;b;b >>= 1, a = (u64) a * a % mod) if(b & 1)
ans = (u64) ans * a % mod;
return ans;
}
void init(int len) {
lim = 2 << std::__lg(len - 1);
invlim = mod - (mod - 1) / lim;
for(static int i = 1;i < lim;i += i) {
wn[i] = 1;
const int w = _pow(3, mod / i / 2);
for(int j = 1;j < i;++j) {
wn[i + j] = (u64) wn[i + j - 1] * w % mod;
}
}
for(int i = 1;i < lim;++i) {
rev[i] = rev[i >> 1] >> 1 | (i % 2u * lim / 2);
}
}
void DFT(int * a) {
static u64 t[N];
for(int i = 0;i < lim;++i) t[i] = a[rev[i]];
for(int i = 1;i < lim;i += i) {
for(int k = i & (1 << 19);k--;)
if(t[k] >= mod * 9ull) t[k] -= mod * 9ull;
for(int j = 0;j < lim;j += i + i) {
for(int k = 0;k < i;++k) {
const u64 x = t[i + j + k] * wn[i + k] % mod;
t[i + j + k] = t[k + j] + (mod - x), t[k + j] += x;
}
}
}
for(int i = 0;i < lim;++i) a[i] = t[i] % mod;
}
void IDFT(int * a) {
DFT(a), std::reverse(a + 1, a + lim);
for(int i = 0;i < lim;++i)
a[i] = (u64) a[i] * invlim % mod;
}
struct oc {
std::vector<int> f, g, res;
std::vector<std::vector<int>> fa, fb;
int n, p;
oc(int n) : f(n), g(n), res(n), n(n), p(0) { }
void push(int v0, int v1) {
f[p] = v0;
res[p] = (res[p] + (u64) f[0] * v1 + (u64) g[0] * v0) % mod;
g[p++] = v1;
static int A[N], B[N];
int lb = p & -p;
init(lb * 2);
memset(A, 0, lim << 2);
memset(B, 0, lim << 2);
for(int i = 0;i < lb;++i) A[i] = g[p - lb + i], B[i] = f[p - lb + i];
DFT(A), DFT(B);
if(lb == p) {
fa.emplace_back(A, A + lim);
fb.emplace_back(B, B + lim);
for(int i = 0;i < lim;++i) A[i] = (u64) A[i] * B[i] % mod;
} else {
auto & C = fb[std::__lg(lim)], & D = fa[std::__lg(lim)];
for(int i = 0;i < lim;++i) A[i] = ((u64) A[i] * C[i * 2] + (u64) B[i] * D[i * 2]) % mod;
}
IDFT(A);
for(int j = p;j < p + lb && j < n;++j) res[j] = (res[j] + A[j - p + lb]) % mod;
}
};
struct Exp : oc {
std::vector<int> res;
Exp(int n) : oc(n), res(n) { }
void push(int v) {
if(!res[0]) return void(res[0] = 1);
oc::push(res[p], v * u64(p + 1) % mod);
res[p] = (u64) oc::res[p - 1] * _inv[p] % mod;
}
};
struct Ln : oc {
std::vector<int> res; int fi;
Ln(int n) : oc(n), res(n), fi(0) {}
void push(int v) {
if(!fi) return void(fi = 1);
oc::push(res[p] * (u64) p % mod, v);
res[p] = ((u64) v * p + mod - oc::res[p - 1]) % mod * _inv[p] % mod;
}
};
struct Inv : oc {
std::vector<int>res; int fi;
Inv(int n) : oc(n), res(n), fi(0) {}
void push(int v) {
res[p] = fi ? (oc::res[p] + (u64) v * res[0]) % mod * (mod - res[0]) % mod : _pow(fi = v, mod - 2);
oc::push(res[p], v);
}
};
int n;
int main() {
_init();
cin>>n;
vector<int> R(n+10), U(n+10);
Inv iU(n+10);
Exp eR(n+10), eRU(n+10);
oc RU(n+10), UeRU(n+10), UUeRU(n+10), _R(n+10), _U(n+10);
rep(i,0,n) {
iU.push(i==0?1:mod-U[i]);
eR.push(R[i]);
RU.push(R[i],U[i]);
eRU.push(RU.res[i]);
UeRU.push(U[i],eRU.res[i]);
UUeRU.push(U[i],UeRU.res[i]);
_R.push(iU.res[i], (mod+eR.res[i]-UUeRU.res[i])%mod);
_U.push(iU.res[i], (mod+eR.res[i]-eRU.res[i])%mod);
R[i+1]=_R.res[i];
U[i+1]=_U.res[i];
}
cout<<(R[n]+U[n])*fac[n]%mod<<'\n';
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 24ms
memory: 13900kb
input:
1
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 24ms
memory: 13896kb
input:
3
output:
24
result:
ok 1 number(s): "24"
Test #3:
score: 0
Accepted
time: 24ms
memory: 13956kb
input:
5
output:
3190
result:
ok 1 number(s): "3190"
Test #4:
score: 0
Accepted
time: 20ms
memory: 13980kb
input:
100
output:
413875584
result:
ok 1 number(s): "413875584"
Test #5:
score: 0
Accepted
time: 20ms
memory: 13948kb
input:
1
output:
1
result:
ok 1 number(s): "1"
Test #6:
score: 0
Accepted
time: 20ms
memory: 13884kb
input:
2
output:
4
result:
ok 1 number(s): "4"
Test #7:
score: 0
Accepted
time: 24ms
memory: 16228kb
input:
3
output:
24
result:
ok 1 number(s): "24"
Test #8:
score: 0
Accepted
time: 20ms
memory: 13948kb
input:
4
output:
236
result:
ok 1 number(s): "236"
Test #9:
score: 0
Accepted
time: 24ms
memory: 16200kb
input:
5
output:
3190
result:
ok 1 number(s): "3190"
Test #10:
score: 0
Accepted
time: 23ms
memory: 14176kb
input:
6
output:
55182
result:
ok 1 number(s): "55182"
Test #11:
score: 0
Accepted
time: 24ms
memory: 13948kb
input:
7
output:
1165220
result:
ok 1 number(s): "1165220"
Test #12:
score: 0
Accepted
time: 24ms
memory: 13892kb
input:
8
output:
29013896
result:
ok 1 number(s): "29013896"
Test #13:
score: 0
Accepted
time: 24ms
memory: 13960kb
input:
9
output:
832517514
result:
ok 1 number(s): "832517514"
Test #14:
score: 0
Accepted
time: 20ms
memory: 16036kb
input:
10
output:
96547079
result:
ok 1 number(s): "96547079"
Test #15:
score: 0
Accepted
time: 20ms
memory: 13896kb
input:
11
output:
296100513
result:
ok 1 number(s): "296100513"
Test #16:
score: 0
Accepted
time: 24ms
memory: 13956kb
input:
12
output:
672446962
result:
ok 1 number(s): "672446962"
Test #17:
score: 0
Accepted
time: 24ms
memory: 13944kb
input:
13
output:
986909297
result:
ok 1 number(s): "986909297"
Test #18:
score: 0
Accepted
time: 24ms
memory: 15996kb
input:
14
output:
306542229
result:
ok 1 number(s): "306542229"
Test #19:
score: 0
Accepted
time: 24ms
memory: 13960kb
input:
15
output:
8548107
result:
ok 1 number(s): "8548107"
Test #20:
score: 0
Accepted
time: 20ms
memory: 15940kb
input:
16
output:
773960239
result:
ok 1 number(s): "773960239"
Test #21:
score: 0
Accepted
time: 24ms
memory: 13964kb
input:
17
output:
611627547
result:
ok 1 number(s): "611627547"
Test #22:
score: 0
Accepted
time: 24ms
memory: 14124kb
input:
18
output:
91793980
result:
ok 1 number(s): "91793980"
Test #23:
score: 0
Accepted
time: 24ms
memory: 16000kb
input:
19
output:
689202618
result:
ok 1 number(s): "689202618"
Test #24:
score: 0
Accepted
time: 24ms
memory: 16008kb
input:
20
output:
605957782
result:
ok 1 number(s): "605957782"
Test #25:
score: 0
Accepted
time: 55ms
memory: 17468kb
input:
10000
output:
713782215
result:
ok 1 number(s): "713782215"
Test #26:
score: 0
Accepted
time: 87ms
memory: 22520kb
input:
20000
output:
337916836
result:
ok 1 number(s): "337916836"
Test #27:
score: 0
Accepted
time: 125ms
memory: 23444kb
input:
30000
output:
580803285
result:
ok 1 number(s): "580803285"
Test #28:
score: 0
Accepted
time: 167ms
memory: 30996kb
input:
40000
output:
732660392
result:
ok 1 number(s): "732660392"
Test #29:
score: 0
Accepted
time: 214ms
memory: 30080kb
input:
50000
output:
660835595
result:
ok 1 number(s): "660835595"
Test #30:
score: 0
Accepted
time: 226ms
memory: 29304kb
input:
60000
output:
323452070
result:
ok 1 number(s): "323452070"
Test #31:
score: 0
Accepted
time: 314ms
memory: 45344kb
input:
70000
output:
307315915
result:
ok 1 number(s): "307315915"
Test #32:
score: 0
Accepted
time: 338ms
memory: 42408kb
input:
80000
output:
951757567
result:
ok 1 number(s): "951757567"
Test #33:
score: 0
Accepted
time: 375ms
memory: 43548kb
input:
90000
output:
426123208
result:
ok 1 number(s): "426123208"
Test #34:
score: 0
Accepted
time: 428ms
memory: 44696kb
input:
100000
output:
827418228
result:
ok 1 number(s): "827418228"
Test #35:
score: 0
Accepted
time: 460ms
memory: 49860kb
input:
110000
output:
541614559
result:
ok 1 number(s): "541614559"
Test #36:
score: 0
Accepted
time: 502ms
memory: 48996kb
input:
120000
output:
184688986
result:
ok 1 number(s): "184688986"
Test #37:
score: 0
Accepted
time: 524ms
memory: 45828kb
input:
130000
output:
898089371
result:
ok 1 number(s): "898089371"
Test #38:
score: 0
Accepted
time: 667ms
memory: 72104kb
input:
140000
output:
949540221
result:
ok 1 number(s): "949540221"
Test #39:
score: 0
Accepted
time: 701ms
memory: 71232kb
input:
150000
output:
767689851
result:
ok 1 number(s): "767689851"
Test #40:
score: 0
Accepted
time: 733ms
memory: 72676kb
input:
160000
output:
553494563
result:
ok 1 number(s): "553494563"
Test #41:
score: 0
Accepted
time: 774ms
memory: 73988kb
input:
170000
output:
270711750
result:
ok 1 number(s): "270711750"
Test #42:
score: 0
Accepted
time: 789ms
memory: 75072kb
input:
180000
output:
108155689
result:
ok 1 number(s): "108155689"
Test #43:
score: 0
Accepted
time: 852ms
memory: 76124kb
input:
190000
output:
327542856
result:
ok 1 number(s): "327542856"
Test #44:
score: 0
Accepted
time: 920ms
memory: 78808kb
input:
200000
output:
236144151
result:
ok 1 number(s): "236144151"
Test #45:
score: 0
Accepted
time: 911ms
memory: 76396kb
input:
198798
output:
16935264
result:
ok 1 number(s): "16935264"
Extra Test:
score: 0
Extra Test Passed