結果

問題 No.801 エレベーター
ユーザー commycommy
提出日時 2019-03-30 19:33:09
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 4,379 bytes
コンパイル時間 1,035 ms
コンパイル使用メモリ 80,592 KB
実行使用メモリ 73,696 KB
最終ジャッジ日時 2023-08-10 12:38:04
合計ジャッジ時間 34,582 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 9 ms
4,380 KB
testcase_04 AC 10 ms
4,380 KB
testcase_05 AC 9 ms
4,376 KB
testcase_06 AC 9 ms
4,380 KB
testcase_07 AC 10 ms
4,380 KB
testcase_08 AC 10 ms
4,376 KB
testcase_09 AC 10 ms
4,384 KB
testcase_10 AC 10 ms
4,384 KB
testcase_11 AC 9 ms
4,376 KB
testcase_12 AC 10 ms
4,380 KB
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 AC 1,742 ms
73,232 KB
testcase_24 AC 1,735 ms
73,232 KB
testcase_25 AC 1,741 ms
73,180 KB
testcase_26 AC 1,744 ms
73,560 KB
testcase_27 AC 1,730 ms
73,428 KB
testcase_28 AC 699 ms
73,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

template<ll MOD = 1000000007>
class ModInt {
    ll n;
    static ModInt pow(ModInt x, ll p) {
        if (p == 0) {
            return 1;
        } else if (p % 2) {
            return x * pow(x, p - 1);
        } else {
            auto t = ModInt::pow(x, p / 2);
            return t * t;
        }
    }
    ModInt reverse() {
        return ModInt::pow(*this, MOD - 2);
    }

public:
    ModInt()
        : n(0) {}
    ModInt(ll _n)
        : n(_n % MOD) {}
    ModInt operator+=(const ModInt &m) {
        n += m.n;
        if (n >= MOD) {
            n -= MOD;
        }
        return *this;
    }
    ModInt operator-=(const ModInt &m) {
        n -= m.n;
        if (n < 0) {
            n += MOD;
        }
        return *this;
    }
    ModInt operator*=(const ModInt &m) {
        n *= m.n;
        if (n >= MOD) {
            n %= MOD;
        }
        return *this;
    }
    ModInt operator/=(const ModInt &m) {
        return n *= reverse(m);
    }

    ModInt operator+=(const ll l) {
        return (*this) += ModInt(l);
    }
    ModInt operator-=(const ll l) {
        return (*this) -= ModInt(l);
    }
    ModInt operator*=(const ll l) {
        return (*this) *= ModInt(l);
    }
    ModInt operator/=(const ll l) {
        return (*this) /= ModInt(l);
    }
    ModInt operator+(const ModInt &m) {
        auto t = *this;
        return t += m;
    }
    ModInt operator-(const ModInt &m) {
        auto t = *this;
        return t -= m;
    }
    ModInt operator*(const ModInt &m) {
        auto t = *this;
        return t *= m;
    }
    ModInt operator/(const ModInt &m) {
        auto t = *this;
        return t /= m;
    }
    ModInt operator+(const ll l) {
        auto t = *this;
        return t += l;
    }
    ModInt operator-(const ll l) {
        auto t = *this;
        return t -= l;
    }
    ModInt operator*(const ll l) {
        auto t = *this;
        return t *= l;
    }
    ModInt operator/(const ll l) {
        auto t = *this;
        return t /= l;
    }
    ModInt operator=(const ll l) {
        n = l % MOD;
        if (n < 0) {
            n += MOD;
        }
        return *this;
    }
    friend ostream &operator<<(ostream &out, const ModInt &m) {
        out << m.n;
        return out;
    }
    friend istream &operator>>(istream &in, ModInt &m) {
        ll l;
        in >> l;
        m = l;
        return in;
    }
};

using MOD = ModInt<>;

class SegmentTree {
    vector<MOD> data;
    int N;

public:
    SegmentTree(int n) {
        N = 1;
        while (N < n) N *= 2;
        data.resize(2 * N - 1, MOD(0));
    }
    void add(int l, int r, MOD val) {
        add(l, r, 0, N, 0, val);
    }
    void add(int l, int r, int a, int b, int x, MOD val) {
        if (b <= l || r <= a) return;
        if (l <= a && b <= r) {
            data[x] += val;
            return;
        }
        int mid = (a + b) / 2;
        add(l, r, a, mid, 2 * x + 1, val);
        add(l, r, mid, b, 2 * x + 2, val);
    }
    MOD get(int pos) {
        pos += N - 1;
        MOD ans = data[pos];
        while (pos > 0) {
            pos = (pos - 1) / 2;
            ans += data[pos];
        }
        return ans;
    }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> L(m), R(m);
    REP(i, 0, m) {
        cin >> L[i] >> R[i];
    }
    auto dp = make_v(k + 1, n, MOD(0));
    dp[0][0] = 1;
    REP (i, 0, k) {
        SegmentTree segtree(n);
        vector<MOD> sum(n + 1, MOD(0));
        REP (j, 0, n) {
            sum[j + 1] += sum[j] + dp[i][j];
        }
        REP (j, 0, m) {
            MOD a = sum[R[j]] - sum[L[j] - 1];
            segtree.add(L[j] - 1, R[j], a);
        }
        REP (j, 0, n) {
            dp[i + 1][j] = segtree.get(j);
        }
    }
    cout << dp[k][n - 1] << endl;
    return 0;
}
0