結果

問題 No.801 エレベーター
ユーザー やむなくやむなく
提出日時 2019-03-17 21:53:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,163 bytes
コンパイル時間 1,880 ms
コンパイル使用メモリ 178,616 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-09-22 05:37:05
合計ジャッジ時間 6,256 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,760 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 56 ms
4,376 KB
testcase_04 AC 58 ms
4,376 KB
testcase_05 AC 55 ms
4,376 KB
testcase_06 AC 55 ms
4,380 KB
testcase_07 AC 57 ms
4,376 KB
testcase_08 AC 60 ms
4,380 KB
testcase_09 AC 55 ms
4,380 KB
testcase_10 AC 57 ms
4,376 KB
testcase_11 AC 55 ms
4,376 KB
testcase_12 AC 56 ms
4,380 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;

#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000

typedef long long LL;
typedef long double LD;

LL inv(LL x){
  int n=MOD-2;
  LL ans=1;
  while(n){
    if(n&1) ans=(ans*x)%MOD;
    n/=2;
    x=x*x%MOD;
  }
  return ans;
}

LL inv2;

struct LazySegmentTree {
private:
  int n;
  vector<LL> node, lazy;

public:
  LazySegmentTree(int size) {
    int sz = size;
    n = 1; while(n < sz) n *= 2;
    node.resize(2*n-1, 0);
    lazy.resize(2*n-1, 0);
  }

  void init(){
    for(int i=0;i<2*n-1;i++){
      node[i]=lazy[i]=0;
    }
  }

  void eval(int k, int l, int r) {
    if(lazy[k] != 0) {
      node[k] = (node[k]+lazy[k])%MOD;
      if(r - l > 1) {
          lazy[2*k+1] = (lazy[2*k+1]+lazy[k] *inv2)%MOD;
          lazy[2*k+2] = (lazy[2*k+2]+lazy[k] *inv2)%MOD;
      }
      lazy[k] = 0;
    }
  }

  void add(int a, int b, LL x, int k=0, int l=0, int r=-1) {
    if(r < 0) r = n;
    eval(k, l, r);
    if(b <= l || r <= a) return;
    if(a <= l && r <= b) {
      lazy[k] = (lazy[k]+(r - l) * x%MOD)%MOD;
      eval(k, l, r);
    }else {
      add(a, b, x, 2*k+1, l, (l+r)/2);
      add(a, b, x, 2*k+2, (l+r)/2, r);
      node[k] = (node[2*k+1] + node[2*k+2])%MOD;
    }
  }

  LL getsum(int a, int b, int k=0, int l=0, int r=-1) {
    if(r < 0) r = n;
    if(b <= l || r <= a) return 0;
    eval(k, l, r);
    if(a <= l && r <= b) return node[k];
    LL vl = getsum(a, b, 2*k+1, l, (l+r)/2);
    LL vr = getsum(a, b, 2*k+2, (l+r)/2, r);
    return (vl + vr)%MOD;
  }
};

int main(){
  int n,m,k;
  cin >> n >> m >> k;
  inv2=inv(2);
  vector<pair<int,int>> p(m);
  for(int i=0;i<m;i++){
    cin >> p[i].first >> p[i].second;
    p[i].first--;
  }

  LazySegmentTree seg(n);
  seg.add(0,1,1);
  vector<LL> sum(m);
  for(int i=0;i<k;i++){
    for(int j=0;j<m;j++){
      sum[j]=seg.getsum(p[j].first,p[j].second);
      // cout << sum[j] << " ";
    }
    // cout << endl;
    seg.init();
    for(int j=0;j<m;j++){
      seg.add(p[j].first,p[j].second,sum[j]);
    }
  }
  cout << seg.getsum(n-1,n) << endl;
  return 0;
}
0