QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#408600#8339. Rooted TreeNelofus#AC ✓302ms198904kbC++202.4kb2024-05-10 19:49:052024-05-10 19:49:06

Judging History

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

  • [2024-05-10 19:49:06]
  • 评测
  • 测评结果:AC
  • 用时:302ms
  • 内存:198904kb
  • [2024-05-10 19:49:05]
  • 提交

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;
}

详细

Test #1:

score: 100
Accepted
time: 99ms
memory: 81716kb

input:

6 2

output:

18

result:

ok 1 number(s): "18"

Test #2:

score: 0
Accepted
time: 89ms
memory: 81572kb

input:

2 6

output:

600000038

result:

ok 1 number(s): "600000038"

Test #3:

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

input:

83 613210

output:

424200026

result:

ok 1 number(s): "424200026"

Test #4:

score: 0
Accepted
time: 201ms
memory: 160388kb

input:

48 6713156

output:

198541581

result:

ok 1 number(s): "198541581"

Test #5:

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

input:

1 111

output:

6216

result:

ok 1 number(s): "6216"

Test #6:

score: 0
Accepted
time: 240ms
memory: 167176kb

input:

28 7304152

output:

457266679

result:

ok 1 number(s): "457266679"

Test #7:

score: 0
Accepted
time: 139ms
memory: 129680kb

input:

38 4101162

output:

232117382

result:

ok 1 number(s): "232117382"

Test #8:

score: 0
Accepted
time: 271ms
memory: 197840kb

input:

51 9921154

output:

340670552

result:

ok 1 number(s): "340670552"

Test #9:

score: 0
Accepted
time: 115ms
memory: 102736kb

input:

79 1801157

output:

620550406

result:

ok 1 number(s): "620550406"

Test #10:

score: 0
Accepted
time: 198ms
memory: 145212kb

input:

22 5417157

output:

457449071

result:

ok 1 number(s): "457449071"

Test #11:

score: 0
Accepted
time: 158ms
memory: 119308kb

input:

25 3210162

output:

36368303

result:

ok 1 number(s): "36368303"

Test #12:

score: 0
Accepted
time: 152ms
memory: 115992kb

input:

67 2919160

output:

935195555

result:

ok 1 number(s): "935195555"

Test #13:

score: 0
Accepted
time: 260ms
memory: 182660kb

input:

77 8613163

output:

482832472

result:

ok 1 number(s): "482832472"

Test #14:

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

input:

90 10000000

output:

275581651

result:

ok 1 number(s): "275581651"

Test #15:

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

input:

99 9999999

output:

126087169

result:

ok 1 number(s): "126087169"

Test #16:

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

input:

100 10000000

output:

451590067

result:

ok 1 number(s): "451590067"

Extra Test:

score: 0
Extra Test Passed