提交记录 5939


用户 题目 状态 得分 用时 内存 语言 代码长度
EntropyIncreaser noi18b. 【NOI2018】冒泡排序 Accepted 100 98.746 ms 17008 KB C++ 1.61 KB
提交时间 评测时间
2018-09-12 14:45:30 2020-08-01 00:36:45
#include <cstdio>
#include <cstring>

using namespace std;

typedef long long ll;

const int N = 600010;
const int P = 998244353;

int p[N];
int fac[N * 2], ifac[N * 2], inv[N * 2];
bool f[N];

void upd(int n);
int comb(int n, int m);
int schroder(int n, int m);

int main() {
	fac[0] = fac[1] = 1;
	ifac[0] = ifac[1] = 1;
	inv[1] = 1;
	int t;
	scanf("%d", &t);
	while (t--) {
		int n;
		scanf("%d", &n);
		for (int i = 1; i <= n; ++i)
			scanf("%d", &p[i]);
		upd(n * 2);
		int ans = 0, pa = 0, pb = 0, a = n, b = n;
		memset(f, 0, sizeof(bool) * (n + 1));
		for (int i = 1; i <= n; ++i) {
			if (p[i] > pa) {
				for (int j = pa + 1; j <= p[i]; ++j)
					if (!f[j])
						--a;
				ans += schroder(b, a - 1);
				if (ans >= P)
					ans -= P;
				pa = p[i];
			} else if (p[i] > pb) {
				if (a > 0) {
					ans += schroder(b, a - 1);
					if (ans >= P)
						ans -= P;
				}
				bool flag = true;
				for (int j = pb + 1; j < p[i]; ++j)
					if (!f[j]) {
						flag = false;
						break;
					}
				if (!flag)
					break;
				pb = p[i];
			}
			--b;
			f[p[i]] = true;
		}
		printf("%d\n", ans);
	}
	return 0;
}

void upd(int n) {
	static int mn = 1;
	if (mn >= n)
		return;
	for (int x = mn + 1; x <= n; ++x)
		inv[x] = -(P / x) * (ll)inv[P % x] % P + P;
	for (int x = mn + 1; x <= n; ++x)
		fac[x] = fac[x - 1] * (ll)x % P;
	for (int x = mn + 1; x <= n; ++x)
		ifac[x] = ifac[x - 1] * (ll)inv[x] % P;
	mn = n;
}

inline int comb(int n, int m) {
	if (m < 0)
		return 0;
	return fac[n] * (ll)ifac[m] % P * ifac[n - m] % P;
}

inline int schroder(int n, int m) {
	int ret = comb(n + m, m) - comb(n + m, m - 1);
	if (ret < 0)
		ret += P;
	return ret;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #114.89 us36 KBAcceptedScore: 4

Testcase #218.49 us36 KBAcceptedScore: 4

Testcase #318.02 us36 KBAcceptedScore: 4

Testcase #415.74 us36 KBAcceptedScore: 4

Testcase #516 us36 KBAcceptedScore: 4

Testcase #616.57 us36 KBAcceptedScore: 4

Testcase #714.37 us36 KBAcceptedScore: 4

Testcase #813.58 us36 KBAcceptedScore: 4

Testcase #914.08 us36 KBAcceptedScore: 4

Testcase #1014.85 us36 KBAcceptedScore: 4

Testcase #1114.06 us36 KBAcceptedScore: 4

Testcase #1234.2 us36 KBAcceptedScore: 4

Testcase #1338.37 us36 KBAcceptedScore: 4

Testcase #1438.8 us40 KBAcceptedScore: 4

Testcase #1542.41 us44 KBAcceptedScore: 4

Testcase #1644.52 us44 KBAcceptedScore: 4

Testcase #17161.42 us64 KBAcceptedScore: 4

Testcase #18170.7 us64 KBAcceptedScore: 4

Testcase #19175.52 us64 KBAcceptedScore: 4

Testcase #20180.62 us64 KBAcceptedScore: 4

Testcase #2158.086 ms7 MB + 420 KBAcceptedScore: 4

Testcase #2272.424 ms9 MB + 256 KBAcceptedScore: 4

Testcase #2390.431 ms12 MB + 332 KBAcceptedScore: 4

Testcase #2497.607 ms15 MB + 404 KBAcceptedScore: 4

Testcase #2598.746 ms16 MB + 624 KBAcceptedScore: 4


Judge Duck Online | 评测鸭在线
Server Time: 2024-12-05 09:56:44 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠