結果

問題 No.1011 Infinite Stairs
ユーザー Plan8Plan8
提出日時 2020-03-20 23:11:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 5,287 bytes
コンパイル時間 2,374 ms
コンパイル使用メモリ 180,800 KB
実行使用メモリ 287,268 KB
最終ジャッジ日時 2024-05-09 01:10:50
合計ジャッジ時間 5,629 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,752 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 82 ms
9,088 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0, sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

template<typename T>
struct BIT{
    private:

    public:
        using Func = function<T(T, T)>;

        int n;
        vector<T> node;

        T init_v;
        Func func;

        BIT(vector<T> a, Func _func, T _init_v) {
            n = a.size() + 1;
            init_v = _init_v;
            func = _func;

            node.resize(n, init_v);
            for(int i=1; i<n; i++) if((i+(i&-i)) < n) node[i+(i&-i)] = func(node[i+(i&-i)], node[i]);
        }

        BIT() {}

        void add(int pos, T v) {
            while(pos < n){
                node[pos] = func(node[pos], v);
                pos += pos & -pos;
            }
        }

        T sum(int pos){
            T res = init_v;
            while(pos > 0){
                res = func(res, node[pos]);
                pos = pos & (pos-1);
            }
            return res;
        }
};

template<typename T>
struct LazyBIT{
    private:
        

    public:
        using Func = function<T(T, T)>;
        using MulInt = function<T(T,int)>;
        using Unary = function<T(T)>;
        BIT<T> bit0, bit1;
        Func _add;
        MulInt _mul;
        Unary _inv;

        LazyBIT(vector<T> a, Func add_func, MulInt mul_func, Unary inv, T _init_v) {
            int n = a.size();
            _add = add_func;
            _mul = mul_func;
            _inv = inv;
            bit0 = BIT<T>(a, add_func, _init_v);
            bit1 = BIT<T>(vector<T>(n,0), add_func, _init_v);
        }

        LazyBIT() {};
        void init(vector<T> a, Func add_func, MulInt mul_func, Unary inv, T _init_v) {
            int n = a.size();
            _add = add_func;
            _mul = mul_func;
            _inv = inv;
            bit0 = BIT<T>(a, add_func, _init_v);
            bit1 = BIT<T>(vector<T>(n,0), add_func, _init_v);
        }

        void add(int l, int r, T v) {
            bit0.add(l, _mul(_inv(v),l-1));
            bit0.add(r+1, _mul(v,r));
            bit1.add(l, v);
            bit1.add(r+1, _inv(v));
        }

        T sum(int pos){
            return _add(_mul(bit1.sum(pos),pos), bit0.sum(pos));
        }
};

struct mint {
    long long x;
    mint(long long x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
    	return *this;
    }
    mint& operator*=(const mint a) {
    	(x *= a.x) %= MOD;
    	return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
    	if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint a) {
    	return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

int main(void){
    auto f = [](ll a, ll b){return (a+b)%MOD;};
    auto g = [](ll a, ll b){return (a*b)%MOD;};
    auto h = [](ll a){return a*(-1) + MOD;};
    auto p = [](ll a, int b){return a*(ll)b;};
    ll N,d,K; cin >> N >> d >> K;
    vector<ll> a(K+1); REP(i,K+1) a[i] = 0;
    LazyBIT<ll> bit[N+1];
    REP(i,N+1) bit[i].init(a,f,g,h,0);
    bit[0].add(1,1,1);
    REP(i,N)REP(j,K){
        ll t = bit[i].sum(j+1) - bit[i].sum(j);
        if(t < 0) t += MOD;
        if(t > 0){
            bit[i+1].add(j+2,min(K+1,j+d+1),t);
        }
    }
    ll ans = bit[N].sum(K+1) - bit[N].sum(K);
    if(ans < 0) ans += MOD;
    cout << ans << en;
    return 0;
}
0