提交记录 5062
| 用户 | 题目 | 状态 | 得分 | 用时 | 内存 | 语言 | 代码长度 |
|---|---|---|---|---|---|---|---|
| EntropyIncreaser | noi18b. 【NOI2018】冒泡排序 | Accepted | 100 | 100.259 ms | 17008 KB | C++ | 1.60 KB |
| 提交时间 | 评测时间 |
|---|---|
| 2018-08-05 23:34:50 | 2020-08-01 00:10:34 |
#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;
}
int comb(int n, int m) {
if (m < 0)
return 0;
return fac[n] * (ll)ifac[m] % P * ifac[n - m] % P;
}
int schroder(int n, int m) {
int ret = comb(n + m, m) - comb(n + m, m - 1);
if (ret < 0)
ret += P;
return ret;
}
| Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
| Testcase #1 | 13.81 us | 36 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #2 | 18.23 us | 36 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #3 | 18.48 us | 36 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #4 | 15.38 us | 36 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #5 | 15.5 us | 36 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #6 | 18.18 us | 36 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #7 | 13.76 us | 36 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #8 | 14.52 us | 36 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #9 | 14.09 us | 36 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #10 | 15.12 us | 36 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #11 | 14.3 us | 36 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #12 | 34.93 us | 36 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #13 | 39.49 us | 36 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #14 | 39.49 us | 40 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #15 | 43.19 us | 44 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #16 | 45.28 us | 44 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #17 | 163.28 us | 64 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #18 | 174.28 us | 64 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #19 | 175.06 us | 64 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #20 | 183.56 us | 64 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #21 | 58.299 ms | 7 MB + 420 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #22 | 73.14 ms | 9 MB + 256 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #23 | 92.216 ms | 12 MB + 332 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #24 | 99.466 ms | 15 MB + 404 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #25 | 100.259 ms | 16 MB + 624 KB | Accepted | Score: 4 | 显示更多 |
Judge Duck Online | 评测鸭在线
Server Time: 2026-04-12 12:57:46 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠