QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#357903#8010. Hierarchies of Judgesucup-team1209AC ✓894ms77428kbC++145.7kb2024-03-19 14:46:542024-03-19 14:46:54

Judging History

你现在查看的是最新测评结果

  • [2024-03-19 14:46:54]
  • 评测
  • 测评结果:AC
  • 用时:894ms
  • 内存:77428kb
  • [2024-03-19 14:46:54]
  • 提交

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) {
        if (!fi) {
            assert(v != 0);
            fi = v;
            res[0] = inv(v);
            oc::push(res[0], v);
            return;
        }
        ll t = (oc::res[p] + (u64) v * res[0]) % mod;
        res[p] = (mod - res[0] * t % mod) % mod;
        oc::push(res[p], v);
    }
};

int n;


int main() {
    file();
    _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,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 24ms
memory: 14080kb

input:

1

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 24ms
memory: 13796kb

input:

3

output:

24

result:

ok 1 number(s): "24"

Test #3:

score: 0
Accepted
time: 24ms
memory: 15924kb

input:

5

output:

3190

result:

ok 1 number(s): "3190"

Test #4:

score: 0
Accepted
time: 17ms
memory: 14148kb

input:

100

output:

413875584

result:

ok 1 number(s): "413875584"

Test #5:

score: 0
Accepted
time: 20ms
memory: 15972kb

input:

1

output:

1

result:

ok 1 number(s): "1"

Test #6:

score: 0
Accepted
time: 19ms
memory: 13992kb

input:

2

output:

4

result:

ok 1 number(s): "4"

Test #7:

score: 0
Accepted
time: 24ms
memory: 15968kb

input:

3

output:

24

result:

ok 1 number(s): "24"

Test #8:

score: 0
Accepted
time: 24ms
memory: 13876kb

input:

4

output:

236

result:

ok 1 number(s): "236"

Test #9:

score: 0
Accepted
time: 24ms
memory: 14112kb

input:

5

output:

3190

result:

ok 1 number(s): "3190"

Test #10:

score: 0
Accepted
time: 24ms
memory: 14172kb

input:

6

output:

55182

result:

ok 1 number(s): "55182"

Test #11:

score: 0
Accepted
time: 24ms
memory: 13996kb

input:

7

output:

1165220

result:

ok 1 number(s): "1165220"

Test #12:

score: 0
Accepted
time: 19ms
memory: 13928kb

input:

8

output:

29013896

result:

ok 1 number(s): "29013896"

Test #13:

score: 0
Accepted
time: 20ms
memory: 13824kb

input:

9

output:

832517514

result:

ok 1 number(s): "832517514"

Test #14:

score: 0
Accepted
time: 24ms
memory: 16224kb

input:

10

output:

96547079

result:

ok 1 number(s): "96547079"

Test #15:

score: 0
Accepted
time: 24ms
memory: 14112kb

input:

11

output:

296100513

result:

ok 1 number(s): "296100513"

Test #16:

score: 0
Accepted
time: 20ms
memory: 15924kb

input:

12

output:

672446962

result:

ok 1 number(s): "672446962"

Test #17:

score: 0
Accepted
time: 24ms
memory: 15936kb

input:

13

output:

986909297

result:

ok 1 number(s): "986909297"

Test #18:

score: 0
Accepted
time: 24ms
memory: 14116kb

input:

14

output:

306542229

result:

ok 1 number(s): "306542229"

Test #19:

score: 0
Accepted
time: 20ms
memory: 13996kb

input:

15

output:

8548107

result:

ok 1 number(s): "8548107"

Test #20:

score: 0
Accepted
time: 20ms
memory: 14180kb

input:

16

output:

773960239

result:

ok 1 number(s): "773960239"

Test #21:

score: 0
Accepted
time: 24ms
memory: 13804kb

input:

17

output:

611627547

result:

ok 1 number(s): "611627547"

Test #22:

score: 0
Accepted
time: 24ms
memory: 15972kb

input:

18

output:

91793980

result:

ok 1 number(s): "91793980"

Test #23:

score: 0
Accepted
time: 20ms
memory: 14124kb

input:

19

output:

689202618

result:

ok 1 number(s): "689202618"

Test #24:

score: 0
Accepted
time: 20ms
memory: 13872kb

input:

20

output:

605957782

result:

ok 1 number(s): "605957782"

Test #25:

score: 0
Accepted
time: 50ms
memory: 17116kb

input:

10000

output:

713782215

result:

ok 1 number(s): "713782215"

Test #26:

score: 0
Accepted
time: 86ms
memory: 24244kb

input:

20000

output:

337916836

result:

ok 1 number(s): "337916836"

Test #27:

score: 0
Accepted
time: 123ms
memory: 21348kb

input:

30000

output:

580803285

result:

ok 1 number(s): "580803285"

Test #28:

score: 0
Accepted
time: 162ms
memory: 27008kb

input:

40000

output:

732660392

result:

ok 1 number(s): "732660392"

Test #29:

score: 0
Accepted
time: 200ms
memory: 28040kb

input:

50000

output:

660835595

result:

ok 1 number(s): "660835595"

Test #30:

score: 0
Accepted
time: 230ms
memory: 31360kb

input:

60000

output:

323452070

result:

ok 1 number(s): "323452070"

Test #31:

score: 0
Accepted
time: 290ms
memory: 41372kb

input:

70000

output:

307315915

result:

ok 1 number(s): "307315915"

Test #32:

score: 0
Accepted
time: 333ms
memory: 46172kb

input:

80000

output:

951757567

result:

ok 1 number(s): "951757567"

Test #33:

score: 0
Accepted
time: 363ms
memory: 41484kb

input:

90000

output:

426123208

result:

ok 1 number(s): "426123208"

Test #34:

score: 0
Accepted
time: 423ms
memory: 46500kb

input:

100000

output:

827418228

result:

ok 1 number(s): "827418228"

Test #35:

score: 0
Accepted
time: 441ms
memory: 49784kb

input:

110000

output:

541614559

result:

ok 1 number(s): "541614559"

Test #36:

score: 0
Accepted
time: 460ms
memory: 46996kb

input:

120000

output:

184688986

result:

ok 1 number(s): "184688986"

Test #37:

score: 0
Accepted
time: 518ms
memory: 45956kb

input:

130000

output:

898089371

result:

ok 1 number(s): "898089371"

Test #38:

score: 0
Accepted
time: 629ms
memory: 69980kb

input:

140000

output:

949540221

result:

ok 1 number(s): "949540221"

Test #39:

score: 0
Accepted
time: 686ms
memory: 73292kb

input:

150000

output:

767689851

result:

ok 1 number(s): "767689851"

Test #40:

score: 0
Accepted
time: 704ms
memory: 72160kb

input:

160000

output:

553494563

result:

ok 1 number(s): "553494563"

Test #41:

score: 0
Accepted
time: 745ms
memory: 75592kb

input:

170000

output:

270711750

result:

ok 1 number(s): "270711750"

Test #42:

score: 0
Accepted
time: 777ms
memory: 73120kb

input:

180000

output:

108155689

result:

ok 1 number(s): "108155689"

Test #43:

score: 0
Accepted
time: 828ms
memory: 75580kb

input:

190000

output:

327542856

result:

ok 1 number(s): "327542856"

Test #44:

score: 0
Accepted
time: 894ms
memory: 77428kb

input:

200000

output:

236144151

result:

ok 1 number(s): "236144151"

Test #45:

score: 0
Accepted
time: 880ms
memory: 76760kb

input:

198798

output:

16935264

result:

ok 1 number(s): "16935264"

Extra Test:

score: 0
Extra Test Passed