結果

問題 No.801 エレベーター
ユーザー polylogKpolylogK
提出日時 2019-03-17 21:57:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,022 bytes
コンパイル時間 2,041 ms
コンパイル使用メモリ 183,840 KB
実行使用メモリ 200,232 KB
最終ジャッジ日時 2023-09-22 05:51:47
合計ジャッジ時間 6,626 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 77 ms
5,668 KB
testcase_04 AC 80 ms
5,364 KB
testcase_05 AC 75 ms
5,484 KB
testcase_06 AC 77 ms
5,476 KB
testcase_07 AC 79 ms
5,380 KB
testcase_08 AC 81 ms
5,472 KB
testcase_09 AC 77 ms
5,804 KB
testcase_10 AC 79 ms
5,432 KB
testcase_11 AC 76 ms
5,452 KB
testcase_12 AC 79 ms
5,544 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

const int MOD = 1e9 + 7;

using namespace std;

template< typename Monoid, typename OperatorMonoid = Monoid >
struct LazySegmentTree
{
  using F = function< Monoid(Monoid, Monoid) >;
  using G = function< Monoid(Monoid, OperatorMonoid) >;
  using H = function< OperatorMonoid(OperatorMonoid, OperatorMonoid) >;
  using P = function< OperatorMonoid(OperatorMonoid, int) >;

  int sz;
  vector< Monoid > data;
  vector< OperatorMonoid > lazy;
  const F f;
  const G g;
  const H h;
  const P p;
  const Monoid M1;
  const OperatorMonoid OM0;


  LazySegmentTree(int n, const F f, const G g, const H h, const P p,
                  const Monoid &M1, const OperatorMonoid OM0)
      : f(f), g(g), h(h), p(p), M1(M1), OM0(OM0)
  {
    sz = 1;
    while(sz < n) sz <<= 1;
    data.assign(2 * sz, M1);
    lazy.assign(2 * sz, OM0);
  }

  void set(int k, const Monoid &x)
  {
    data[k + sz] = x;
  }

  void build()
  {
    for(int k = sz - 1; k > 0; k--) {
      data[k] = f(data[2 * k + 0], data[2 * k + 1]);
    }
  }

  void propagate(int k, int len)
  {
    if(lazy[k] != OM0) {
      if(k < sz) {
        lazy[2 * k + 0] = h(lazy[2 * k + 0], lazy[k]);
        lazy[2 * k + 1] = h(lazy[2 * k + 1], lazy[k]);
      }
      data[k] = g(data[k], p(lazy[k], len));
      lazy[k] = OM0;
    }
  }

  Monoid update(int a, int b, const OperatorMonoid &x, int k, int l, int r)
  {
    propagate(k, r - l);
    if(r <= a || b <= l) {
      return data[k];
    } else if(a <= l && r <= b) {
      lazy[k] = h(lazy[k], x);
      propagate(k, r - l);
      return data[k];
    } else {
      return data[k] = f(update(a, b, x, 2 * k + 0, l, (l + r) >> 1),
                         update(a, b, x, 2 * k + 1, (l + r) >> 1, r));
    }
  }

  Monoid update(int a, int b, const OperatorMonoid &x)
  {
    return update(a, b, x, 1, 0, sz);
  }


  Monoid query(int a, int b, int k, int l, int r)
  {
    propagate(k, r - l);
    if(r <= a || b <= l) {
      return M1;
    } else if(a <= l && r <= b) {
      return data[k];
    } else {
      return f(query(a, b, 2 * k + 0, l, (l + r) >> 1),
               query(a, b, 2 * k + 1, (l + r) >> 1, r));
    }
  }

  Monoid query(int a, int b)
  {
    return query(a, b, 1, 0, sz);
  }

  Monoid operator[](const int &k)
  {
    return query(k, k + 1);
  }
};


int main() {
	int n, m, k; scanf("%d%d%d", &n, &m, &k);
	std::vector<int> l(m), r(m);
	for(int i = 0; i < m; i++) {
		scanf("%d%d", &l[i], &r[i]);
		
		l[i]--;
	}
	
	auto f = [](int a, int b) { return (a + b) % MOD; };;
	auto p = [](int a, int b) { return (i64)a * (i64)b % MOD; };
	std::vector<LazySegmentTree<int>> dp(k + 1, LazySegmentTree<int>(n, f, f, f, p, 0, 0));
	dp[0].update(0, 1, 1);
	for(int i = 0; i < k; i++) {
		for(int j = 0; j < m; j++) {
			int tmp = dp[i].query(l[j], r[j]);
			dp[i + 1].update(l[j], r[j], tmp);
		}
	}
	printf("%d\n", dp[k][n - 1]);
	return 0;
}
0