結果

問題 No.2605 Pickup Parentheses
ユーザー Jeroen Op de BeekJeroen Op de Beek
提出日時 2024-01-12 21:48:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 4,889 bytes
コンパイル時間 2,596 ms
コンパイル使用メモリ 209,192 KB
実行使用メモリ 814,024 KB
最終ジャッジ日時 2024-01-12 21:49:41
合計ジャッジ時間 27,309 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
23,368 KB
testcase_01 AC 34 ms
23,368 KB
testcase_02 AC 33 ms
23,368 KB
testcase_03 AC 36 ms
23,368 KB
testcase_04 AC 36 ms
23,368 KB
testcase_05 AC 38 ms
23,368 KB
testcase_06 AC 41 ms
23,496 KB
testcase_07 AC 38 ms
23,368 KB
testcase_08 AC 42 ms
23,496 KB
testcase_09 AC 35 ms
23,368 KB
testcase_10 AC 41 ms
23,368 KB
testcase_11 AC 37 ms
23,368 KB
testcase_12 AC 35 ms
23,368 KB
testcase_13 AC 34 ms
23,368 KB
testcase_14 AC 39 ms
23,496 KB
testcase_15 AC 40 ms
23,496 KB
testcase_16 AC 34 ms
23,368 KB
testcase_17 AC 37 ms
23,368 KB
testcase_18 AC 486 ms
25,900 KB
testcase_19 AC 283 ms
24,568 KB
testcase_20 AC 73 ms
23,624 KB
testcase_21 AC 55 ms
23,496 KB
testcase_22 AC 41 ms
23,496 KB
testcase_23 AC 526 ms
25,992 KB
testcase_24 AC 70 ms
23,644 KB
testcase_25 AC 601 ms
26,256 KB
testcase_26 AC 593 ms
26,060 KB
testcase_27 AC 508 ms
25,952 KB
testcase_28 AC 651 ms
26,800 KB
testcase_29 AC 147 ms
24,136 KB
testcase_30 AC 308 ms
24,648 KB
testcase_31 AC 295 ms
24,892 KB
testcase_32 AC 137 ms
23,880 KB
testcase_33 AC 655 ms
26,812 KB
testcase_34 AC 590 ms
26,744 KB
testcase_35 AC 476 ms
26,700 KB
testcase_36 AC 559 ms
26,688 KB
testcase_37 AC 585 ms
26,284 KB
testcase_38 AC 140 ms
24,840 KB
testcase_39 AC 63 ms
23,504 KB
testcase_40 AC 303 ms
25,568 KB
testcase_41 AC 276 ms
26,192 KB
testcase_42 AC 414 ms
26,684 KB
testcase_43 AC 95 ms
23,880 KB
testcase_44 AC 91 ms
23,888 KB
testcase_45 AC 34 ms
23,368 KB
testcase_46 AC 53 ms
23,500 KB
testcase_47 AC 34 ms
23,368 KB
testcase_48 AC 185 ms
26,448 KB
testcase_49 AC 435 ms
26,652 KB
testcase_50 AC 190 ms
24,744 KB
testcase_51 AC 376 ms
26,364 KB
testcase_52 AC 228 ms
24,784 KB
testcase_53 AC 357 ms
26,124 KB
testcase_54 AC 186 ms
24,848 KB
testcase_55 AC 323 ms
26,584 KB
testcase_56 AC 92 ms
24,008 KB
testcase_57 AC 388 ms
26,644 KB
testcase_58 AC 738 ms
26,976 KB
testcase_59 AC 537 ms
26,452 KB
testcase_60 AC 664 ms
26,536 KB
testcase_61 AC 652 ms
26,620 KB
testcase_62 AC 637 ms
26,232 KB
testcase_63 AC 640 ms
26,616 KB
testcase_64 AC 735 ms
26,576 KB
testcase_65 AC 557 ms
26,580 KB
testcase_66 AC 905 ms
26,472 KB
testcase_67 AC 619 ms
26,628 KB
testcase_68 MLE -
testcase_69 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define all(x) begin(x),end(x)
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; }
#define debug(a) cerr << "(" << #a << ": " << a << ")\n";
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
const int mxN = 1<<20, oo = 1e9;
const long long MD = 998244353;
template<long long MOD=MD> struct mdint {
    int d;
    mdint () {d=0;}
    mdint (long long _d) : d(_d%MOD){
        if(d<0) d+=MOD;
    };
    friend mdint& operator+=(mdint& a, const mdint& o) {
        a.d+=o.d; if(a.d>=MOD) a.d-=MOD;
        return a;
    }
    friend mdint& operator-=(mdint& a, const mdint& o) {
        a.d-=o.d; if(a.d<0) a.d+=MOD;
        return a;
    }
    friend mdint& operator*=(mdint& a, const mdint& o) {
        return a = mdint((ll)a.d*o.d);
    }
    mdint operator*(const mdint& o) const {
        mdint res = *this;
        res*=o;
        return res;
    }
    mdint operator+(const mdint& o) const {
        mdint res = *this;
        res+=o;
        return res;
    }
    mdint operator-(const mdint& o) const {
        mdint res = *this;
        res-=o;
        return res;
    }
    mdint operator^(long long b) const {
        mdint tmp = 1;
        mdint power = *this;
        while(b) {
            if(b&1) {
                tmp = tmp*power;
            }
            power = power*power;
            b/=2;
        }
        return tmp;
    }
    friend mdint operator/=(mdint& a, const mdint& o) {
        a *= (o^(MOD-2));
        return a;
    }
    mdint operator/(const mdint& o) {
        mdint res = *this;
        res/=o;
        return res;
    }
    bool operator==(const mdint& o) { return d==o.d;}
    bool operator!=(const mdint& o) { return d!=o.d;}
    friend istream& operator>>(istream& c, mdint& a) {return c >> a.d;}
    friend ostream& operator<<(ostream& c, const mdint& a) {return c << a.d;}
};
using  mint = mdint<MD>;
const int mxF = 2e6+2;
mint fact[mxF], ifact[mxF];
mint ncr(int a, int b) {
    if(b>a or a<0 or b<0) return 0;
    return fact[a]*ifact[b]*ifact[a-b];
}
void precomp() {
    fact[0]=1;
    for(int i=1;i<mxF;++i) {
        fact[i]=fact[i-1]*i;
    }
    ifact[mxF-1] = mint(1)/fact[mxF-1];
    for(int i=mxF-2;i>=0;--i) {
        ifact[i]=ifact[i+1]*(i+1);
    }
}

typedef mint cd;
void revperm(cd* in, int n) {
    for(int i=0,j=0;i<n;++i) {
        if(i<j) swap(in[i],in[j]);
        for(int k = n >> 1; (j ^= k) < k; k >>= 1);
    }
}
cd w[mxN+1]; // stores w^j for each j in [0,n-1]
void precomp2() {
    w[0] = 1;
    int pw = (MD-1)/mxN;
    w[1] = mint(3)^pw;
    for(int i= 2;i<=mxN;++i) {
        w[i] = w[i-1]*w[1];
    }
}
void fft(cd* in, int n, bool reverse=false) {
    int lg = __lg(n);
    assert(1<<lg == n);
    int stride = mxN/n;
    revperm(in,n);
    for(int s=1;s<=lg;++s) {
        int pw = 1<<s;
        int mstride = stride*(n>>s);
        for(int j=0;j<n;j+=pw) {
            // do FFT merging on out array
            cd* even = in+j, *odd = in+j+pw/2;
            for(int i=0;i<pw/2;++i) {
                cd& power = w[reverse?mxN-mstride*i:mstride*i];
                auto tmp = power*odd[i];
                odd[i] = even[i] - tmp;
                even[i] = even[i] + tmp;
            }
        }
    }
    if(reverse) {
        mint fac = mint(1)/n;
        for(int i=0;i<n;++i) in[i]=in[i]*fac;
    }
}

vector<cd> polymul(vector<cd> a, vector<cd> b) {
    int n = a.size(), m = b.size(), ptwo = 1;
    while(ptwo<(n+m)) ptwo*=2;
    a.resize(ptwo), b.resize(ptwo);
    fft(a.data(),ptwo); 
    fft(b.data(),ptwo);
    for(int i=0;i<ptwo;++i) 
        a[i] = a[i]*b[i];
    fft(a.data(),ptwo,true);
    a.resize(n+m-1);
    return a;
}
mint catalan(int n) {
    if(n%2==1) return 0;
    n/=2;
    return ncr(2*n,n)/(n+1);
}
int main() {
    precomp();
    precomp2();
    int n,m; cin >> n >> m;
    vi ws(m);
    for(int i=0;i<m;++i) {
        int l,r; cin >> l >> r;
        --l,--r;
        ws[i] = r-l+1;

    }
    auto mul = [&](auto&& self, int l, int r) -> vector<mint> {
        // cerr << l << ' ' << r << '\n';
        if(l+1==r) {
            vector<mint> v(ws[l]+1);
            v[ws[l]]=mint(0)-catalan(ws[l]);
            v[0]+=1;
            return v;
        }
        auto mid = (l+r)/2;
        return polymul(self(self,l,mid), self(self,mid,r));
    };
    auto res = mul(mul,0,m);
    // normally: n brackets
    mint ans=0;
    for(int i=0;i<res.size();++i) {
        ans+=catalan(n-i)*res[i];
    }
    cout << ans << '\n';
}
0