結果

問題 No.801 エレベーター
ユーザー commycommy
提出日時 2019-03-30 19:46:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,026 bytes
コンパイル時間 760 ms
コンパイル使用メモリ 80,756 KB
実行使用メモリ 73,856 KB
最終ジャッジ日時 2024-04-28 06:31:39
合計ジャッジ時間 34,252 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 12 ms
5,376 KB
testcase_04 AC 10 ms
5,376 KB
testcase_05 AC 9 ms
5,376 KB
testcase_06 AC 10 ms
5,376 KB
testcase_07 AC 10 ms
5,376 KB
testcase_08 AC 11 ms
5,376 KB
testcase_09 AC 11 ms
5,376 KB
testcase_10 AC 11 ms
5,376 KB
testcase_11 AC 11 ms
5,376 KB
testcase_12 AC 11 ms
5,376 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,866 ms
73,472 KB
testcase_24 AC 1,828 ms
73,472 KB
testcase_25 TLE -
testcase_26 AC 1,845 ms
73,600 KB
testcase_27 AC 1,851 ms
73,472 KB
testcase_28 AC 880 ms
73,856 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...));
}

const ll mod = 1000000007;

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

public:
    SegmentTree(int n) {
        N = 1;
        while (N < n) N *= 2;
        data.resize(2 * N - 1, 0LL);
    }
    void add(int l, int r, ll val) {
        add(l, r, 0, N, 0, val);
    }
    void add(int l, int r, int a, int b, int x, ll val) {
        if (b <= l || r <= a) return;
        if (l <= a && b <= r) {
            data[x] = (data[x] + val) % mod;
            return;
        }
        int mid = (a + b) / 2;
        add(l, r, a, mid, 2 * x + 1, val);
        add(l, r, mid, b, 2 * x + 2, val);
    }
    ll get(int pos) {
        pos += N - 1;
        ll ans = data[pos];
        while (pos > 0) {
            pos = (pos - 1) / 2;
            ans = (ans + data[pos]) % mod;
        }
        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, 0LL);
    dp[0][0] = 1;
    REP(i, 0, k) {
        SegmentTree segtree(n);
        vector<ll> sum(n + 1, 0LL);
        REP(j, 0, n) {
            sum[j + 1] = (sum[j] + dp[i][j]) % mod;
        }
        REP(j, 0, m) {
            ll a = (sum[R[j]] - sum[L[j] - 1] + mod) % mod;
            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