QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#408747#8339. Rooted TreeNelofusAC ✓289ms198900kbC++202.2kb2024-05-10 23:01:092024-05-10 23:01:09

Judging History

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

  • [2024-05-10 23:01:09]
  • 评测
  • 测评结果:AC
  • 用时:289ms
  • 内存:198900kb
  • [2024-05-10 23:01:09]
  • 提交

answer

// Code by Heratino & Nelofus
// Narcissus & ?????????

#include <bits/stdc++.h>
using i64 = long long;

//{{{??????? ? ?????
template<typename Ta, typename Tb>
inline void chkmax(Ta &a, const Tb &b) {if (a < b)	a = b;}
template<typename Ta, typename Tb>
inline void chkmin(Ta &a, const Tb &b) {if (a > b)	a = b;}
char buf[1 << 20], *P1, *P2;
inline char gc() {
	if (P1 == P2)
		P2 = (P1 = buf) + fread(buf, 1, 1 << 20, stdin);
	return P1 == P2 ? EOF : *P1++;
}
template<typename T>
inline void read(T &ans) {
	ans = 0;
	T w = 1;
	char c = gc();
	while (!isdigit(c)) {
		if (c == '-')	w = -1;
		c = gc();
	}
	while (isdigit(c)) {
		ans = (ans << 3) + (ans << 1) + (c ^ 48);
		c = gc();
	}
	ans *= w;
}
template<typename T, typename ...Ts>
void read(T &a, Ts&... other) {
	read(a);
	read(other...);
}
//}}}

constexpr int mod = 1e9 + 9;
constexpr int N = 1e7 + 10;
inline int Plus(const int &x, const int &y) {return x + y >= mod ? x + y - mod : x + y;}
inline int Minu(const int &x, const int &y) {return x - y < 0 ? x - y + mod : x - y;}
inline int f_pow(int x, int k) {
	int base = 1;
	for (; k; k >>= 1, x = 1ll * x * x % mod)
		if (k & 1)
			base = 1ll * base * x % mod;
	return base;
}

int m, k;
int ifac[N];
int fac[N];
int ED[N];
int pinvf[N], pinvq[N];

inline int inv(int x) {
	return x ? 1ll * ifac[x] * fac[x - 1] % mod : 1;
}

int main() {
#ifdef HeratinoNelofus
	freopen("input.txt", "r", stdin);
#endif

	fac[0] = 1;
	for (int i = 1; i < N; i++)
		fac[i] = 1ll * fac[i - 1] * i % mod;
	ifac[N - 1] = f_pow(fac[N - 1], mod - 2);
	for (int i = N - 2; i >= 0; i--)
		ifac[i] = 1ll * ifac[i + 1] * (i + 1) % mod;

	read(m, k);

	auto invpinv = [&](const int &x) -> int {
		return Plus(1ll * (x - 1) * (m - 1) % mod, 1);
	};
	pinvf[0] = 1;
	for (int i = 1; i <= k; i++)
		pinvf[i] = 1ll * pinvf[i - 1] * invpinv(i) % mod;
	pinvq[k] = f_pow(pinvf[k], mod - 2);
	for (int i = k - 1; i >= 0; i--)
		pinvq[i] = 1ll * pinvq[i + 1] * invpinv(i + 1) % mod;

	ED[0] = 0;
	int ans = 0;
	for (int i = 1; i <= k; i++) {
		int pinv = 1ll * pinvq[i] * pinvf[i - 1] % mod;
		ans = Plus(ans, Plus(1ll * ED[i - 1] * pinv % mod, 1));
		ED[i] = 1ll * ED[i - 1] * (Plus(1ll * i * (m - 1) % mod, 1)) % mod * pinv % mod;
		ED[i] = Plus(ED[i], m);
	}
	std::cout << 1ll * m * ans % mod << '\n';
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 96ms
memory: 81712kb

input:

6 2

output:

18

result:

ok 1 number(s): "18"

Test #2:

score: 0
Accepted
time: 95ms
memory: 81724kb

input:

2 6

output:

600000038

result:

ok 1 number(s): "600000038"

Test #3:

score: 0
Accepted
time: 101ms
memory: 88968kb

input:

83 613210

output:

424200026

result:

ok 1 number(s): "424200026"

Test #4:

score: 0
Accepted
time: 205ms
memory: 160380kb

input:

48 6713156

output:

198541581

result:

ok 1 number(s): "198541581"

Test #5:

score: 0
Accepted
time: 76ms
memory: 81788kb

input:

1 111

output:

6216

result:

ok 1 number(s): "6216"

Test #6:

score: 0
Accepted
time: 235ms
memory: 167308kb

input:

28 7304152

output:

457266679

result:

ok 1 number(s): "457266679"

Test #7:

score: 0
Accepted
time: 166ms
memory: 129644kb

input:

38 4101162

output:

232117382

result:

ok 1 number(s): "232117382"

Test #8:

score: 0
Accepted
time: 268ms
memory: 198048kb

input:

51 9921154

output:

340670552

result:

ok 1 number(s): "340670552"

Test #9:

score: 0
Accepted
time: 120ms
memory: 102728kb

input:

79 1801157

output:

620550406

result:

ok 1 number(s): "620550406"

Test #10:

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

input:

22 5417157

output:

457449071

result:

ok 1 number(s): "457449071"

Test #11:

score: 0
Accepted
time: 157ms
memory: 119244kb

input:

25 3210162

output:

36368303

result:

ok 1 number(s): "36368303"

Test #12:

score: 0
Accepted
time: 162ms
memory: 115996kb

input:

67 2919160

output:

935195555

result:

ok 1 number(s): "935195555"

Test #13:

score: 0
Accepted
time: 265ms
memory: 182612kb

input:

77 8613163

output:

482832472

result:

ok 1 number(s): "482832472"

Test #14:

score: 0
Accepted
time: 280ms
memory: 198792kb

input:

90 10000000

output:

275581651

result:

ok 1 number(s): "275581651"

Test #15:

score: 0
Accepted
time: 289ms
memory: 198900kb

input:

99 9999999

output:

126087169

result:

ok 1 number(s): "126087169"

Test #16:

score: 0
Accepted
time: 285ms
memory: 198896kb

input:

100 10000000

output:

451590067

result:

ok 1 number(s): "451590067"

Extra Test:

score: 0
Extra Test Passed