提交记录 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;
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Testcase #1 | 14.89 us | 36 KB | Accepted | Score: 4 | 显示更多 |
Testcase #2 | 18.49 us | 36 KB | Accepted | Score: 4 | 显示更多 |
Testcase #3 | 18.02 us | 36 KB | Accepted | Score: 4 | 显示更多 |
Testcase #4 | 15.74 us | 36 KB | Accepted | Score: 4 | 显示更多 |
Testcase #5 | 16 us | 36 KB | Accepted | Score: 4 | 显示更多 |
Testcase #6 | 16.57 us | 36 KB | Accepted | Score: 4 | 显示更多 |
Testcase #7 | 14.37 us | 36 KB | Accepted | Score: 4 | 显示更多 |
Testcase #8 | 13.58 us | 36 KB | Accepted | Score: 4 | 显示更多 |
Testcase #9 | 14.08 us | 36 KB | Accepted | Score: 4 | 显示更多 |
Testcase #10 | 14.85 us | 36 KB | Accepted | Score: 4 | 显示更多 |
Testcase #11 | 14.06 us | 36 KB | Accepted | Score: 4 | 显示更多 |
Testcase #12 | 34.2 us | 36 KB | Accepted | Score: 4 | 显示更多 |
Testcase #13 | 38.37 us | 36 KB | Accepted | Score: 4 | 显示更多 |
Testcase #14 | 38.8 us | 40 KB | Accepted | Score: 4 | 显示更多 |
Testcase #15 | 42.41 us | 44 KB | Accepted | Score: 4 | 显示更多 |
Testcase #16 | 44.52 us | 44 KB | Accepted | Score: 4 | 显示更多 |
Testcase #17 | 161.42 us | 64 KB | Accepted | Score: 4 | 显示更多 |
Testcase #18 | 170.7 us | 64 KB | Accepted | Score: 4 | 显示更多 |
Testcase #19 | 175.52 us | 64 KB | Accepted | Score: 4 | 显示更多 |
Testcase #20 | 180.62 us | 64 KB | Accepted | Score: 4 | 显示更多 |
Testcase #21 | 58.086 ms | 7 MB + 420 KB | Accepted | Score: 4 | 显示更多 |
Testcase #22 | 72.424 ms | 9 MB + 256 KB | Accepted | Score: 4 | 显示更多 |
Testcase #23 | 90.431 ms | 12 MB + 332 KB | Accepted | Score: 4 | 显示更多 |
Testcase #24 | 97.607 ms | 15 MB + 404 KB | Accepted | Score: 4 | 显示更多 |
Testcase #25 | 98.746 ms | 16 MB + 624 KB | Accepted | Score: 4 | 显示更多 |
Judge Duck Online | 评测鸭在线
Server Time: 2024-12-05 09:56:44 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠