QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#719160#8339. Rooted TreeTheForsaking#AC ✓1088ms3956kbC++203.3kb2024-11-06 22:57:152024-11-06 22:57:15

Judging History

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

  • [2024-11-06 22:57:15]
  • 评测
  • 测评结果:AC
  • 用时:1088ms
  • 内存:3956kb
  • [2024-11-06 22:57:15]
  • 提交

answer

#include <iostream>
#include <sstream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <queue> 
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <ctime>
#include <assert.h>
#include <deque>
#include <list>
#include <stack>

 
using namespace std;

#define is_mul_overflow(a, b) \
    ((b != 0) && (a > LLONG_MAX / b || a < LLONG_MIN / b))
 
typedef pair<long long, int> pli;
typedef pair<int, long long> pil;
typedef pair<long long , long long> pll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<int, pii> piii;
typedef pair<int, long long > pil;
typedef pair<long long, pii> plii;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ull, ull> puu;
typedef long double ld;
const int N = 2000086, MOD = 1e9 + 9, INF = 0x3f3f3f3f, MID = 333;
const double EPS = 1e-5;
// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
// int dx[8] = {2, 1, -1, -2, -2, -1, 1, 2}, dy[8] = {1, 2, 2, 1, -1, -2, -2, -1};
int n, m, cnt, w[N];
vector<ll> num;
ll res;

ll lowbit(ll x) { return x & -x; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
inline double rand(double l, double r) { return (double)rand() / RAND_MAX * (r - l) + l; }
inline ll qmi(ll a, ll b, ll c) { ll res = 1; while (b) { if (b & 1) res = res * a % c; a = a * a % c; b >>= 1; } return res; }
inline ll qmi(ll a, ll b) { ll res = 1; while (b) { if (b & 1) res *= a; a *= a; b >>= 1; } return res; }
inline double qmi(double a, ll b) { double res = 1; while (b) { if (b & 1) res *= a; a *= a; b >>= 1; } return res; } 
inline ll C(ll a, ll b) { if (a < b) return 0; if (b > a - b) b = a - b; ll res = 1; for (ll i = 1, j = a; i <= b; i++, j--) { res = res * (j % MOD) % MOD; res = res * qmi(i, MOD - 2, MOD) % MOD; } return res; }
inline ll C(ll a, ll b, int* c) { if (a < b) return 0; ll res = 1; for (ll j = a, i = 1; i < b + 1; i++, j--) res *= j; for (ll j = a, i = 1; i < b + 1; i++, j--) res /= i; return res; }
inline int find_(int x) { return lower_bound(num.begin(), num.end(), x) - num.begin(); }

struct pair_hash {
    template <class T1, class T2>
    std::size_t operator() (const std::pair<T1, T2>& pair) const {
        return std::hash<T1>()(pair.first) ^ std::hash<T2>()(pair.second);
    }
};

int e[N], ne[N], h[N], idx, din[N], v, v2;
bool st[N];
inline void add(int a, int b) { e[idx] = b, ne[idx] = h[a], h[a] = idx++; }

void dfs(int r, int fa, int& start) {
    st[r] = 1;
    for (int i = h[r]; ~i; i = ne[i]) {
        int j = e[i];
        if (j == fa) continue;
        if (st[j]) {
            start = j;
            num.push_back(i);
            return;
        }
        dfs(j, r, start);
        if (start) {
            num.push_back(i);
            if (r == start) start = 0;
            return;
        }
    }
    st[r] = 0;
}

inline void solve() {
}

int main() {
    cin >> n >> m;
    ll p = 0, sum = 1;
    for (int i = 1; i < m + 1; i++) {
        res = (res + (p + 1) * n) % MOD;
        sum--;
        p = (p * sum + n * (p + 1)) % MOD * qmi(sum + n, MOD - 2, MOD) % MOD;
        sum += n;
    }
    printf("%lld\n", res);
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3776kb

input:

6 2

output:

18

result:

ok 1 number(s): "18"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3852kb

input:

2 6

output:

600000038

result:

ok 1 number(s): "600000038"

Test #3:

score: 0
Accepted
time: 67ms
memory: 3848kb

input:

83 613210

output:

424200026

result:

ok 1 number(s): "424200026"

Test #4:

score: 0
Accepted
time: 730ms
memory: 3768kb

input:

48 6713156

output:

198541581

result:

ok 1 number(s): "198541581"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3888kb

input:

1 111

output:

6216

result:

ok 1 number(s): "6216"

Test #6:

score: 0
Accepted
time: 794ms
memory: 3784kb

input:

28 7304152

output:

457266679

result:

ok 1 number(s): "457266679"

Test #7:

score: 0
Accepted
time: 446ms
memory: 3848kb

input:

38 4101162

output:

232117382

result:

ok 1 number(s): "232117382"

Test #8:

score: 0
Accepted
time: 1078ms
memory: 3776kb

input:

51 9921154

output:

340670552

result:

ok 1 number(s): "340670552"

Test #9:

score: 0
Accepted
time: 196ms
memory: 3768kb

input:

79 1801157

output:

620550406

result:

ok 1 number(s): "620550406"

Test #10:

score: 0
Accepted
time: 589ms
memory: 3900kb

input:

22 5417157

output:

457449071

result:

ok 1 number(s): "457449071"

Test #11:

score: 0
Accepted
time: 349ms
memory: 3776kb

input:

25 3210162

output:

36368303

result:

ok 1 number(s): "36368303"

Test #12:

score: 0
Accepted
time: 314ms
memory: 3956kb

input:

67 2919160

output:

935195555

result:

ok 1 number(s): "935195555"

Test #13:

score: 0
Accepted
time: 937ms
memory: 3896kb

input:

77 8613163

output:

482832472

result:

ok 1 number(s): "482832472"

Test #14:

score: 0
Accepted
time: 1088ms
memory: 3828kb

input:

90 10000000

output:

275581651

result:

ok 1 number(s): "275581651"

Test #15:

score: 0
Accepted
time: 1083ms
memory: 3892kb

input:

99 9999999

output:

126087169

result:

ok 1 number(s): "126087169"

Test #16:

score: 0
Accepted
time: 1088ms
memory: 3776kb

input:

100 10000000

output:

451590067

result:

ok 1 number(s): "451590067"

Extra Test:

score: 0
Extra Test Passed