QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#686194#8339. Rooted TreeNCl3AC ✓1392ms42712kbC++203.1kb2024-10-29 08:00:002024-10-29 08:00:00

Judging History

你现在查看的是最新测评结果

  • [2024-10-29 08:00:00]
  • 评测
  • 测评结果:AC
  • 用时:1392ms
  • 内存:42712kb
  • [2024-10-29 08:00:00]
  • 提交

answer

#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using ull = unsigned long long;
constexpr int N = 1e7 + 10;
constexpr int inf = 1e9 + 10;
constexpr ll llinf = 1e18 + 10;
constexpr int mod = 1e9 + 9;
void debug() {
    std::cerr << "\n";
}
template<typename T, typename... Args>
void debug(T val, const Args&... args) {
    std::cerr << val << " ";
    debug(args...);
}
template<typename T>
void debug(const std::vector<T>& vec) {
    for (const T& x : vec) std::cerr << x << ' ';std::cerr << "\n";
}
template <typename T>
T power(T a, int b) {
    T ans = 1;
    while (b) {
        if (b & 1) ans *= a;
        a *= a;
        b >>= 1;
    }
    return ans;
}
template <int M>
struct modint {
    modint() : x(0) {}
    template <typename T> modint(T n) { n %= M; if (n < 0) n += M; this->x = n; }

    modint& operator+=(const modint& r) { x += r.x; if (x >= M) x -= M; return *this; }
    modint& operator-=(const modint& r) { x -= r.x; if (x < 0) x += M; return *this; }
    modint& operator*=(const modint& r) { x = (int)((long long)x * r.x % M); return *this; }
    modint inv(long long k = M - 2) const { return power(*this, k); }
    modint& operator/=(const modint& r) { return *this *= r.inv(); }

    modint& operator--() { if (--x == -1) x = M - 1; return *this; }
    modint& operator++() { if (++x == M) x = 0; return *this; }
    modint operator--(int) { modint t = *this; --*this; return t; }
    modint operator++(int) { modint t = *this; ++*this; return t; }

    modint operator-() const { return 0 - *this; }
    modint operator+() const { return *this; }
    constexpr int mod() const { return M; }

    friend modint operator+(modint l, const modint& r) { return l += r; }
    friend modint operator-(modint l, const modint& r) { return l -= r; }
    friend modint operator*(modint l, const modint& r) { return l *= r; }
    friend modint operator/(modint l, const modint& r) { return l /= r; }

    friend bool operator==(const modint& l, const modint& r) { return l.x == r.x; }
    friend bool operator!=(const modint& l, const modint& r) { return l.x != r.x; }
    friend std::istream& operator>>(std::istream& in, modint& r) { return in >> r.x; }
    friend std::ostream& operator<<(std::ostream& out, const modint& r) { return out << r.x; }

    int x;
};
using mint = modint<mod>;
mint f[N];
void ncl3() {
    int n, m;
    std::cin >> m >> n;
    for (ll i = 0; i < n; i++) {
        f[i + 1] = f[i] + (m * f[i] - f[i] + i * m + (i * m + 1 - i) * m) * mint(i * m + 1 - i).inv();
    }
    std::cout << f[n] << "\n";
}
/*
    预处理、找性质缩小范围、集合思想、正难则反、穷举
*/
int main() {
#ifdef LOCAL
    clock_t time = clock();
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#endif
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int t = 1;
    // std::cin >> t;
    while (t--) {
        ncl3();
    }
#ifdef LOCAL
    std::cout << "Time Used:" << clock() - time << "ms" << "\n";
#endif
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 5ms
memory: 42640kb

input:

6 2

output:

18

result:

ok 1 number(s): "18"

Test #2:

score: 0
Accepted
time: 3ms
memory: 42712kb

input:

2 6

output:

600000038

result:

ok 1 number(s): "600000038"

Test #3:

score: 0
Accepted
time: 84ms
memory: 42680kb

input:

83 613210

output:

424200026

result:

ok 1 number(s): "424200026"

Test #4:

score: 0
Accepted
time: 931ms
memory: 42640kb

input:

48 6713156

output:

198541581

result:

ok 1 number(s): "198541581"

Test #5:

score: 0
Accepted
time: 7ms
memory: 42632kb

input:

1 111

output:

6216

result:

ok 1 number(s): "6216"

Test #6:

score: 0
Accepted
time: 1014ms
memory: 42704kb

input:

28 7304152

output:

457266679

result:

ok 1 number(s): "457266679"

Test #7:

score: 0
Accepted
time: 572ms
memory: 42636kb

input:

38 4101162

output:

232117382

result:

ok 1 number(s): "232117382"

Test #8:

score: 0
Accepted
time: 1374ms
memory: 42712kb

input:

51 9921154

output:

340670552

result:

ok 1 number(s): "340670552"

Test #9:

score: 0
Accepted
time: 252ms
memory: 42696kb

input:

79 1801157

output:

620550406

result:

ok 1 number(s): "620550406"

Test #10:

score: 0
Accepted
time: 756ms
memory: 42632kb

input:

22 5417157

output:

457449071

result:

ok 1 number(s): "457449071"

Test #11:

score: 0
Accepted
time: 448ms
memory: 42644kb

input:

25 3210162

output:

36368303

result:

ok 1 number(s): "36368303"

Test #12:

score: 0
Accepted
time: 404ms
memory: 42708kb

input:

67 2919160

output:

935195555

result:

ok 1 number(s): "935195555"

Test #13:

score: 0
Accepted
time: 1195ms
memory: 42636kb

input:

77 8613163

output:

482832472

result:

ok 1 number(s): "482832472"

Test #14:

score: 0
Accepted
time: 1392ms
memory: 42656kb

input:

90 10000000

output:

275581651

result:

ok 1 number(s): "275581651"

Test #15:

score: 0
Accepted
time: 1388ms
memory: 42680kb

input:

99 9999999

output:

126087169

result:

ok 1 number(s): "126087169"

Test #16:

score: 0
Accepted
time: 1392ms
memory: 42628kb

input:

100 10000000

output:

451590067

result:

ok 1 number(s): "451590067"

Extra Test:

score: 0
Extra Test Passed