Submission #931100

# Submission time Handle Problem Language Result Execution time Memory
931100 2024-02-21T08:33:50 Z Pring A Huge Tower (CEOI10_tower) C++17
100 / 100
521 ms 47044 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3","unroll-loops")
#pragma GCC target("avx2","popcnt")
using namespace std;

#ifdef MIKU
#define debug(x...) cout << '[' << #x << "] : ", dout(x)
void dout() { cout << endl; }
template <typename T, typename ...U>
void dout(T t, U ...u) { cout << t << (sizeof...(u) ? ", " : ""); dout(u...); }
#else
#define debug(...) 39
#endif

#define int long long
#define fs first
#define sc second
#define mp make_pair
#define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++)
typedef pair<int, int> pii;

const int MXN = 1000005, mod = 1000000009;
int n, d, a[MXN];

int ADD(int a, int b) {
    a += b;
    a -= (a >= mod ? mod : 0);
    return a;
}

int MUL(int a, int b) {
    return a * b % mod;
}

struct SMG {
    int val[MXN * 4], tag[MXN * 4];
    void add_tag(int id, int t) {
        val[id] = MUL(val[id], t);
        tag[id] = MUL(tag[id], t); 
    }
    void push(int id) {
        if (tag[id] == 1) return;
        add_tag(id * 2 + 1, tag[id]);
        add_tag(id * 2 + 2, tag[id]);
        tag[id] = 1;
    }
    void pull(int id) {
        val[id] = ADD(val[id * 2 + 1], val[id * 2 + 2]);
    }
    void build(int id, int l, int r) {
        val[id] = r - l;
        tag[id] = 1;
        if (l + 1 == r) return;
        int mid = (l + r) >> 1;
        build(id * 2 + 1, l, mid);
        build(id * 2 + 2, mid, r);
    }
    void modify(int id, int l, int r, int _l, int _r, int v) {
        if (_r <= l || r <= _l) return;
        if (_l <= l && r <= _r) {
            add_tag(id, v);
            return;
        }
        int mid = (l + r) >> 1;
        push(id);
        modify(id * 2 + 1, l, mid, _l, _r, v);
        modify(id * 2 + 2, mid, r, _l, _r, v);
        pull(id);
    }
    int query(int id, int l, int r, int _l, int _r) {
        if (_r <= l || r <= _l) return 0;
        if (_l <= l && r <= _r) return val[id];
        int mid = (l + r) >> 1;
        push(id);
        return ADD(query(id * 2 + 1, l, mid, _l, _r), query(id * 2 + 2, mid, r, _l, _r));
    }
    void DFS(int id, int l, int r) {
        if (l + 1 == r) {
            cout << val[id] << ' ';
            return;
        }
        int mid = (l + r) >> 1;
        DFS(id * 2 + 1, l, mid);
        DFS(id * 2 + 2, mid, r);
    }
} smg;

void miku() {
    cin >> n >> d;
    FOR(i, 0, n) cin >> a[i];
    sort(a, a + n);
    int p = 0;
    smg.build(0, 0, n);
    FOR(i, 1, n) {
        while (a[p] + d < a[i]) p++;
        smg.modify(0, 0, n, i, i + 1, smg.query(0, 0, n, p, i));
        smg.modify(0, 0, n, 0, p, i - p + 1);
        smg.modify(0, 0, n, p, i, i - p);
        // smg.DFS(0, 0, n);
        // cout << '\n';
    }
    cout << smg.val[0] << '\n';
}

int32_t main() {
    cin.tie(0) -> sync_with_stdio(false);
    cin.exceptions(iostream::failbit);
    miku();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 6744 KB Output is correct
2 Correct 29 ms 7004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 184 ms 14932 KB Output is correct
2 Correct 120 ms 17236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 304 ms 41556 KB Output is correct
2 Correct 521 ms 47044 KB Output is correct