QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#115157#6323. Range NEQSingleZombie#AC ✓165ms37232kbC++142.8kb2023-06-24 18:20:382023-06-24 18:20:39

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-24 18:20:39]
  • 评测
  • 测评结果:AC
  • 用时:165ms
  • 内存:37232kb
  • [2023-06-24 18:20:38]
  • 提交

answer

#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
#include <map>
#include <set>
#include <bitset>
#include <ctime>
#include <cassert>
#include <complex>

const int INF = 0x3f3f3f3f;
const long long INFLL = 0x3f3f3f3f3f3f3f3fll;
#define memset0(x) memset(x, 0, sizeof(x))
#define memsetM1(x) memset(x, -1, sizeof(x))
#define memsetINF(x) memset(x, INF, sizeof(x))

using namespace std;
using ll = long long;
const ll MOD = 998244353;

const int P = 998244353, N = 1e6 + 5, g = 3;

long long power(ll a, int b)
{
	long long ans = 1;
	long long t;
	for (t = a; b; b >>= 1)
	{
		if (b & 1)	ans *= t; ans %= P;
		t *= t; t %= P;
	}
	return ans;
}

ll wn[N + 5];
void get_wn()
{
	for (int i = 0; i < 23; i++)
	{
		int t = 1 << i;
		wn[i] = power(g, (P - 1) / t);
	}
}

void change(ll y[], int n)
{
	for (int i = 1, j = n >> 1; i < n - 1; i++)
	{
		if (i < j)	swap(y[i], y[j]);
		int k = n / 2;
		while (j >= k && j)
		{
			j -= k;
			k >>= 1;
		}
		if (j < k)	j += k;
	}
}

//sgn == -1 : Inverse
void ntt(ll y[], int n, int sgn = 1)
{
	change(y, n);
	int id = 0;
	for (int h = 2; h <= n; h <<= 1)
	{
		id++;
		for (int j = 0; j < n; j += h)
		{
			ll w = 1;
			for (int k = j; k < j + h / 2; k++)
			{
				ll u = y[k];
				ll t = 1ll * w * y[k + h / 2] % P;
				y[k] = (u + t) % P;
				y[k + h / 2] = ((u - t) % P + P) % P;
				w = (1ll * w * wn[id]) % P;
			}
		}
	}

	if (sgn == -1)
	{
		for (int i = 1; i < n / 2; i++)
			swap(y[i], y[n - i]);
		ll inv = power(n, P - 2);
		for (int i = 0; i < n; i++)
			y[i] = 1ll * y[i] * inv % P;
	}
}

int sum[N + 10];
char str1[N + 10], str2[N + 10];
ll x2[2 * N + 10];
ll fac[N], inv[N], invFac[N];
int n, m;

ll getC(int a, int b)
{
	if (a - b < 0)
	{
		return 0;
	}
	return fac[a] * invFac[b] % MOD * invFac[a - b] % MOD;
}

ll getA(int a, int b)
{
	if (a - b < 0)
	{
		return 0;
	}
	return fac[a] * invFac[a - b] % MOD;
}

int main()
{
	
	cin >> n >> m;
	fac[0] = fac[1] = inv[0] = inv[1] = invFac[0] = invFac[1] = 1;
	for (int i = 2; i <= n * m; i++)
	{
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = ll(MOD - MOD / i) * inv[MOD % i] % MOD;
		invFac[i] = invFac[i - 1] * inv[i] % MOD;
	}
	get_wn();
	int d = 1;
	while (d <= n * m)
	{
		d <<= 1;
	}
	for (int i = 0; i <= m; i++)
	{
		x2[i] = getC(m, i) * getA(m, i) % MOD;
	}


	ntt(x2, d);
	for (int i = 0; i < d; i++)
		x2[i] = power(x2[i], n);
	ntt(x2, d, -1);
	
	ll ans = 0;
	ll psgn = 1;
	for (int i = 1; i <= n * m; i++)
	{
		ans = (ans + psgn * x2[i] * fac[n * m - i] % MOD) % MOD;
		psgn *= -1;
	}
	ans = ((fac[n * m] - ans) % MOD + MOD) % MOD;
	cout << ans << endl;

	return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 11596kb

input:

2 2

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 1ms
memory: 11604kb

input:

5 1

output:

44

result:

ok 1 number(s): "44"

Test #3:

score: 0
Accepted
time: 2ms
memory: 11872kb

input:

167 91

output:

284830080

result:

ok 1 number(s): "284830080"

Test #4:

score: 0
Accepted
time: 2ms
memory: 11464kb

input:

2 1

output:

1

result:

ok 1 number(s): "1"

Test #5:

score: 0
Accepted
time: 2ms
memory: 11752kb

input:

2 3

output:

36

result:

ok 1 number(s): "36"

Test #6:

score: 0
Accepted
time: 2ms
memory: 11748kb

input:

2 4

output:

576

result:

ok 1 number(s): "576"

Test #7:

score: 0
Accepted
time: 1ms
memory: 11528kb

input:

3 1

output:

2

result:

ok 1 number(s): "2"

Test #8:

score: 0
Accepted
time: 1ms
memory: 11520kb

input:

3 2

output:

80

result:

ok 1 number(s): "80"

Test #9:

score: 0
Accepted
time: 1ms
memory: 11528kb

input:

3 3

output:

12096

result:

ok 1 number(s): "12096"

Test #10:

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

input:

3 4

output:

4783104

result:

ok 1 number(s): "4783104"

Test #11:

score: 0
Accepted
time: 2ms
memory: 11528kb

input:

4 1

output:

9

result:

ok 1 number(s): "9"

Test #12:

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

input:

4 2

output:

4752

result:

ok 1 number(s): "4752"

Test #13:

score: 0
Accepted
time: 2ms
memory: 11668kb

input:

4 3

output:

17927568

result:

ok 1 number(s): "17927568"

Test #14:

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

input:

4 4

output:

776703752

result:

ok 1 number(s): "776703752"

Test #15:

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

input:

5 2

output:

440192

result:

ok 1 number(s): "440192"

Test #16:

score: 0
Accepted
time: 2ms
memory: 11532kb

input:

5 3

output:

189125068

result:

ok 1 number(s): "189125068"

Test #17:

score: 0
Accepted
time: 1ms
memory: 11528kb

input:

5 4

output:

975434093

result:

ok 1 number(s): "975434093"

Test #18:

score: 0
Accepted
time: 163ms
memory: 37004kb

input:

1000 1000

output:

720037464

result:

ok 1 number(s): "720037464"

Test #19:

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

input:

72 42

output:

638177567

result:

ok 1 number(s): "638177567"

Test #20:

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

input:

15 19

output:

663050288

result:

ok 1 number(s): "663050288"

Test #21:

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

input:

68 89

output:

94365047

result:

ok 1 number(s): "94365047"

Test #22:

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

input:

92 37

output:

652605307

result:

ok 1 number(s): "652605307"

Test #23:

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

input:

61 87

output:

498277867

result:

ok 1 number(s): "498277867"

Test #24:

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

input:

81 40

output:

133095344

result:

ok 1 number(s): "133095344"

Test #25:

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

input:

7 91

output:

524164813

result:

ok 1 number(s): "524164813"

Test #26:

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

input:

31 18

output:

361233485

result:

ok 1 number(s): "361233485"

Test #27:

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

input:

74 54

output:

500686087

result:

ok 1 number(s): "500686087"

Test #28:

score: 0
Accepted
time: 2ms
memory: 11520kb

input:

32 2

output:

586504335

result:

ok 1 number(s): "586504335"

Test #29:

score: 0
Accepted
time: 75ms
memory: 26832kb

input:

656 718

output:

346764298

result:

ok 1 number(s): "346764298"

Test #30:

score: 0
Accepted
time: 36ms
memory: 16588kb

input:

254 689

output:

358078813

result:

ok 1 number(s): "358078813"

Test #31:

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

input:

713 674

output:

914437613

result:

ok 1 number(s): "914437613"

Test #32:

score: 0
Accepted
time: 15ms
memory: 14484kb

input:

136 698

output:

56687290

result:

ok 1 number(s): "56687290"

Test #33:

score: 0
Accepted
time: 35ms
memory: 16420kb

input:

369 401

output:

312325811

result:

ok 1 number(s): "312325811"

Test #34:

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

input:

280 204

output:

280012063

result:

ok 1 number(s): "280012063"

Test #35:

score: 0
Accepted
time: 37ms
memory: 18572kb

input:

904 225

output:

162909174

result:

ok 1 number(s): "162909174"

Test #36:

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

input:

855 928

output:

39885159

result:

ok 1 number(s): "39885159"

Test #37:

score: 0
Accepted
time: 37ms
memory: 18568kb

input:

503 365

output:

745115888

result:

ok 1 number(s): "745115888"

Test #38:

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

input:

646 996

output:

610925577

result:

ok 1 number(s): "610925577"

Test #39:

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

input:

990 918

output:

203469632

result:

ok 1 number(s): "203469632"

Test #40:

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

input:

961 949

output:

169566857

result:

ok 1 number(s): "169566857"

Test #41:

score: 0
Accepted
time: 161ms
memory: 37232kb

input:

946 932

output:

352423195

result:

ok 1 number(s): "352423195"

Test #42:

score: 0
Accepted
time: 163ms
memory: 37200kb

input:

903 981

output:

196309824

result:

ok 1 number(s): "196309824"

Test #43:

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

input:

916 988

output:

487208972

result:

ok 1 number(s): "487208972"

Test #44:

score: 0
Accepted
time: 155ms
memory: 37064kb

input:

982 982

output:

387421488

result:

ok 1 number(s): "387421488"

Test #45:

score: 0
Accepted
time: 153ms
memory: 37068kb

input:

955 911

output:

955637031

result:

ok 1 number(s): "955637031"

Test #46:

score: 0
Accepted
time: 165ms
memory: 37088kb

input:

906 999

output:

798469943

result:

ok 1 number(s): "798469943"

Test #47:

score: 0
Accepted
time: 155ms
memory: 37232kb

input:

982 975

output:

193506289

result:

ok 1 number(s): "193506289"

Test #48:

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

input:

921 991

output:

431202149

result:

ok 1 number(s): "431202149"