結果

問題 No.801 エレベーター
ユーザー utouto97utouto97
提出日時 2019-03-18 23:23:57
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,454 bytes
コンパイル時間 1,482 ms
コンパイル使用メモリ 158,548 KB
実行使用メモリ 8,752 KB
最終ジャッジ日時 2023-09-26 13:24:04
合計ジャッジ時間 6,308 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
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 int long long
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
}*/

class SqrtDecomposition
{
public:
  int n, k, d;
  vector<int> data, bucket, lazy;
  vector<bool> lazyflag;
  int block;

  SqrtDecomposition(int n_, int d_, int block_=512): n(n_), d(d_), block(block_)
  {
    k = (n+block-1) / block;
    data.assign(k*block, d);
    bucket.assign(k, d);
    lazy.assign(k, 0);
    lazyflag.assign(k, false);
  }

  void eval(int x)
  {
    if(lazyflag[x]){
      lazyflag[x] = false;
      for(int i = x*block; i < (x+1)*block; i++){
        data[i] += lazy[x];
        data[i] %= mod;
      }
    }
  }

  void update(int s, int t, int x)
  {
    for(int i = 0; i < k; i++){
      int l = i*block, r = (i+1)*block;
      if(r <= s or t <= l) continue;
      if(s <= l and r <= t){
        bucket[i] += x*block%mod;
        bucket[i] %= mod;
        lazy[i] = x;
        lazyflag[i] = true;
      }else{
        eval(i); 
        for(int j = max(s, l); j < min(t, r); j++){
          data[j] += x;
          data[j] %= mod;
        }
        bucket[i] = d;
        for(int j = l; j < r; j++){
          bucket[i] += data[j];
          bucket[i] %= mod;
        }
      }
    }
  }

  void update(int i, int x)
  {
    update(i, i+1, x);
  }

  int find(int s, int t)
  {
    int res = d;
    for(int i = 0; i < k; i++){
      int l = i*block, r = (i+1)*block;
      if(r <= s or t <= l) continue; 
      if(s <= l and r <= t){
        res += bucket[i];
        res %= mod;
      }else{
        eval(i);
        for(int j = max(s, l); j < min(t, r); j++){
          res += data[j];
          res %= mod;
        }
      }
    }

    return res;
  }

  int find(int i)
  {
    return find(i, i+1);
  }
};

signed main()
{
  int n, m, k;
  cin >> n >> m >> k;

  vi l(m), r(m);
  rep(i, m) cin >> l[i] >> r[i];

  vector<SqrtDecomposition> sd(k+1, SqrtDecomposition(n, 0, sqrt(3000)));
  sd[0].update(1, 1);
  repi(i, 1, k+1){
    rep(j, m){
      int t = sd[i-1].find(l[j], r[j]+1);
      sd[i].update(l[j], r[j]+1, t);
    }
  }

  cout << (sd[k].find(n) % mod) << endl;

  return 0;
}
0