QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#745818#9631. Median ReplacementDeltaxWA 0ms3576kbC++142.4kb2024-11-14 11:46:172024-11-14 11:46:18

Judging History

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

  • [2024-11-14 11:46:18]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3576kb
  • [2024-11-14 11:46:17]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mkp make_pair
#define pb push_back
typedef pair <int, int> pii;

inline int read() {
	int x = 0, f = 0;
	char c = getchar();
	while (!isdigit(c)) {if (c == '-') f = 1; c = getchar();}
	while (isdigit(c)) x = (x << 1) + (x << 3) + (c & 15), c = getchar();
	return f? -x : x;
}

const int MAXN = 300;
const int Mod = 998244353;
int l[MAXN + 10], r[MAXN + 10];
int DP(int n, int x) {
	static int dp[MAXN + 10][2][2];
	dp[0][0][0] = 1;
	int res = 1;
	for (int i = 1; i <= n; ++i) {
		res = 1ll * res * (r[i] - l[i] + 1) % Mod;
		dp[i][0][0] = 1ll * (dp[i - 1][1][0] + dp[i - 1][0][0]) * max(0, (x - l[i])) % Mod;
		dp[i][1][0] = 1ll * dp[i - 1][0][1] * max(0, (x - l[i])) % Mod;
		dp[i][0][1] = 1ll * dp[i - 1][0][0] * max(0, r[i] - x + 1) % Mod;
	}
	int sum = ((dp[n][0][0] + dp[n][0][1]) % Mod + dp[n][1][0]) % Mod;
	return (res - sum + Mod) % Mod;
}

inline int fastpow(int x, int p) {
	int ans = 1;
	while (p) {
		if (p & 1) ans = 1ll * ans * x % Mod;
		x = 1ll * x * x % Mod;
		p >>= 1;
	}
	return ans;
}
int Lan(int *X, int *Y, int n, int k) {
	int prod = 1, ans = 0;
	for (int i = 1; i <= n; ++i) {
		int res = 1;
		for (int j = 1; j <= n; ++j)
			if (j != i) prod = 1ll * prod * (X[i] - X[j]) % Mod, res = 1ll * res * (k - X[j]) % Mod;
		prod = fastpow(prod, Mod - 2);
		ans = (ans + 1ll * res * Y[i] % Mod * prod) % Mod;
	}
	return ans;
}

int main() {
//	freopen ("std.in", "r", stdin);
//	freopen ("std.out", "w", stdout);
	int T = read();
	while (T--) {
		int n = read();
		for (int i = 1; i <= n; ++i) l[i] = read();
		for (int i = 1; i <= n; ++i) r[i] = read();
		static int b[MAXN + 10], tot = 0;
		for (int i = 1; i <= n; ++i) b[++tot] = l[i];
		for (int i = 1; i <= n; ++i) b[++tot] = r[i] + 1;
		sort(b + 1, b + tot + 1);
		tot = unique(b + 1, b + tot + 1) - b - 1;
		int ans = 0;
		for (int i = 1; i < tot; ++i) {
			int L = b[i], R = b[i + 1] - 1;
			int len = min(R - L + 1, 200);
			static int X[MAXN + 10], Y[MAXN + 10];
			for (int j = 1; j <= len; ++j) {
				X[j] = L + j - 1;
				Y[j] = DP(n, X[j]);
			}
			for (int j = 2; j <= len; ++j)
				Y[j] = (Y[j - 1] + Y[j]) % Mod;
			if (len == R - L + 1) {
				ans = (ans + Y[len]) % Mod;
			}
			else {
				ans = (ans + Lan(X, Y, len, R) - Lan(X, Y, len, L - 1)) % Mod;
				ans = (ans + Mod) % Mod;
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3576kb

input:

10
5
5 1 4 3 2
14 2 5 3 2
5
4 5 1 2 3
13 7 1 2 3
5
5 2 5 3 1
10 2 12 3 2
5
5 5 3 1 5
57 5 3 1 5
5
2 2 3 3 5
4 5 4 4 5
5
4 5 3 5 3
13 7 3 5 3
5
5 1 4 2 3
14 3 4 2 3
5
1 2 5 4 5
2 8 5 7 5
5
1 1 3 5 1
8 2 3 8 1
5
4 4 4 2 3
5 10 5 2 3

output:

997764433
997823621
997885511
140525608
632337589
90596780
636513115
828369051
241944941
817773985

result:

wrong answer 1st lines differ - expected: '180', found: '997764433'