結果

問題 No.1973 Divisor Sequence
ユーザー k1suxuk1suxu
提出日時 2022-06-10 23:49:05
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,817 bytes
コンパイル時間 3,655 ms
コンパイル使用メモリ 260,108 KB
実行使用メモリ 7,800 KB
最終ジャッジ日時 2023-10-21 05:53:37
合計ジャッジ時間 17,024 ms
ジャッジサーバーID
(参考情報)
judge9 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 TLE -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 57 ms
4,348 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 TLE -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define rep(i,n) for(int i = 0; i < (int)n; i++)
#define FOR(n) for(int i = 0; i < (int)n; i++)
#define repi(i,a,b) for(int i = (int)a; i < (int)b; i++)
#define pb push_back
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
//#define mp make_pair
#define vi vector<int>
#define vvi vector<vi>
#define vll vector<ll>
#define vvll vector<vll>
#define vs vector<string>
#define vvs vector<vs>
#define vc vector<char>
#define vvc vector<vc>
#define pii pair<int,int>
#define pllll pair<ll,ll>
#define vpii vector<pair<int,int>>
#define vpllll vector<pair<ll,ll>>
#define vpis vector<pair<int,string>>
#define vplls vector<pair<ll, string>>
#define vpsi vector<pair<string, int>>
#define vpsll vector<pair<string, ll>>

template<typename T>
void chmax(T &a, const T &b) {a = (a > b? a : b);}
template<typename T>
void chmin(T &a, const T &b) {a = (a < b? a : b);}

using ll = long long;
using ld = long double;
using ull = unsigned long long;

const ll INF = numeric_limits<long long>::max() / 2;
const ld pi = 3.1415926535897932384626433832795028;
const ll mod = 1e9 + 7;
int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1};
int dy[] = {0, -1, 0, 1, -1, 1, -1, 1};

#define int long long

template<typename T>
struct RSQ_RAQ {
    const T e = 0;
    const T zero = 0;
    vector<T> dat, lazy;
    int n;
    function<T(T, T)> fx = [](T x, T y) {return (x + y) % mod;};

    RSQ_RAQ(int n_) : n(), dat(4*n_, e), lazy(4*n_, zero) {
        int x = 1;
        while(x < n_) x *= 2;
        n = x;
    }

    void evaluate(int length, int k) {
        if(lazy[k] == zero) return;
        if(k <= n - 2) {
            (lazy[k * 2 + 1] += lazy[k]) %= mod;
            (lazy[k * 2 + 2] += lazy[k]) %= mod;
        }
        (dat[k] += lazy[k] * length % mod) %= mod;
        lazy[k] = zero;
    }

    void add(int a, int b, T x) {
        return add_sub(a, b, x, 0, 0, n);
    }
    void add_sub(int a, int b, T x, int k, int l, int r) {
        evaluate(r - l, k);
        if(a <= l && r <= b) {
            (lazy[k] += x) %= mod;
            evaluate(r - l, k);
        }else if(a < r && l < b) {
            add_sub(a, b, x, k * 2 + 1, l, (l + r) / 2);
            add_sub(a, b, x, k * 2 + 2, (l + r) / 2, r);
            dat[k] = fx(dat[k * 2 + 1], dat[k * 2 + 2]);
        }
    }

    T query(int a, int b) {
        return query_sub(a, b, 0, 0, n);
    }
    T query_sub(int a, int b, int k, int l, int r) {
        evaluate(r - l, k);
        if(r <= a || b <= l) {
            return e;
        }else if(a <= l && r <= b) {
            return dat[k];
        }else {
            T vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2);
            T vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r);
            return fx(vl, vr);
        }
    }
};

vector<int> quotients(const int n) {
    vector<int> ret;

    for(int i = 1; i * i <= n; i++) {
        if(n%i != 0) continue;
        ret.push_back(i);
        if(i * i  != n) ret.push_back(n / i);
    }

    sort(all(ret));
    return ret;
}

void solve() {
    int n, m;
    cin >> n >> m;

    vi quots = quotients(m);
    //a[i]*a[i+1]がmを超えないような数列の数
    int sz = quots.size();

    RSQ_RAQ<int> tree(sz);
    FOR(sz) tree.add(i, i+1, 1);

    FOR(n-1) {
        RSQ_RAQ<int> ntree(sz);

        int id = 0;
        for(auto e : quots) {
            ntree.add(id, id+1, tree.query(0LL, (int)(upper_bound(all(quots), m/e) - quots.begin())));
            id++;
        }

        FOR(sz) tree.add(i, i+1, (ntree.query(i, i+1) - tree.query(i, i+1)) % mod);
    }

    cout << (tree.query(0, sz) % mod + mod) % mod << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}
0