#include <vector>
#include <set>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <queue>
#define pb push_back
#define fi first
#define se second
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define ALL(a) a.begin(), a.end()
#define lowbit(x) ((x) & -(x))
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, int> pii;
typedef pair<int, int> pi;
typedef vector<int> VI;
namespace io {
const int L = (1 << 21) + 1;
char ibuf[L], *iS, *iT, obuf[L], *oS = obuf, *oT = obuf + L - 1, c, qu[55]; int f, qr;
#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, L, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
inline void flush () { fwrite (obuf, 1, oS - obuf, stdout); oS = obuf; }
inline void putc (char x) { *oS ++ = x; if (oS == oT) flush (); }
template <class I> inline void gi (I & x) {
for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
for (x = 0; c <= '9' && c >= '0'; c = gc()) x = x * 10 + (c & 15); x *= f;
}
template <class I> inline void print (I x) {
if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
while (x) qu[++ qr] = x % 10 + '0', x /= 10;
while (qr) putc (qu[qr --]);
}
inline char read () {
for (c = gc(); c < 'a' || c > 'z'; c = gc());
return c;
}
inline void gs (char *s) {
int l;
for (c = gc(); c < 'a' || c > 'z'; c = gc());
for (l = 0; c <= 'z' && c >= 'a'; c = gc()) s[l] = c, ++l;
s[l] = 0;
}
inline void ps (const char *s) {
int l = strlen(s), i;
for (i = 0; i < l; i ++) putc(s[i]);
}
struct IOC { ~ IOC () { flush (); } } _ioc_;
} ;
using io::gi;
using io::gs;
using io::ps;
using io::putc;
using io::read;
using io::print;
template <class T> inline bool chkmin(T &a, T b) { return b < a ? a = b, true : false; }
template <class T> inline bool chkmax(T &a, T b) { return a < b ? a = b, true : false; }
const int N = 1200005, P = 998244353;
int fpow(int a, int t){
static int r;
for (r = 1; t; t >>= 1, a = (ll)a * a % P) if (t & 1) r = (ll)r * a % P;
return r;
}
int T, n, low, p[N], q[N], fac[N], ifac[N], inv[N], len[N], ret;
bool vis[N];
int binom(int n, int m){ return n < m ? 0 : (ll)fac[n] * ifac[m] % P * ifac[n - m] % P; }
int cal(int n, int m){
return (binom(n + m, m) - binom(n + m, n + 1) + P) % P;
}
int main(){
freopen("inverse.in", "r", stdin), freopen("inverse.out", "w", stdout);
int i, j, x;
fac[0] = ifac[0] = fac[1] = ifac[1] = inv[1] = 1;
for (i = 2; i < N; i ++) {
fac[i] = (ll)fac[i - 1] * i % P;
inv[i] = P - (ll)(P / i) * inv[P % i] % P;
ifac[i] = (ll)ifac[i - 1] * inv[i] % P;
}
for (gi(T); T; --T) {
gi(n);
for (i = 1; i <= n; i ++) gi(p[i]);
for (ret = j = 0, low = i = 1; i <= n; i ++) {
chkmax(j, p[i]), len[n - i] = n - j;
for (vis[p[i]] = true; vis[low]; ++low);
if (p[i] < j && p[i] > low) break;
}
for (i = 0; i < n; i ++) {
x = 0;
if (i) chkmax(x, len[i - 1] - 1);
for (j = x; j < len[i]; j ++) ret = (ret + binom(i + j, i)) % P;
if (i == n - 1) for (j = 1; j < len[i]; j ++) ret = (ret - binom(i + j, j - 1)) % P;
}
ret = (ret + P) % P;
print(ret), putc('\n');
for (i = 1; i <= n; i ++) len[i - 1] = vis[i] = 0;
}
return 0;
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Testcase #1 | 11.913 ms | 13 MB + 796 KB | Accepted | Score: 4 | 显示更多 |
Testcase #2 | 11.936 ms | 13 MB + 796 KB | Accepted | Score: 4 | 显示更多 |
Testcase #3 | 11.911 ms | 13 MB + 796 KB | Accepted | Score: 4 | 显示更多 |
Testcase #4 | 11.919 ms | 13 MB + 796 KB | Accepted | Score: 4 | 显示更多 |
Testcase #5 | 11.916 ms | 13 MB + 796 KB | Accepted | Score: 4 | 显示更多 |
Testcase #6 | 11.916 ms | 13 MB + 796 KB | Accepted | Score: 4 | 显示更多 |
Testcase #7 | 11.919 ms | 13 MB + 796 KB | Accepted | Score: 4 | 显示更多 |
Testcase #8 | 11.912 ms | 13 MB + 796 KB | Accepted | Score: 4 | 显示更多 |
Testcase #9 | 11.938 ms | 13 MB + 796 KB | Accepted | Score: 4 | 显示更多 |
Testcase #10 | 11.923 ms | 13 MB + 796 KB | Accepted | Score: 4 | 显示更多 |
Testcase #11 | 11.919 ms | 13 MB + 796 KB | Accepted | Score: 4 | 显示更多 |
Testcase #12 | 11.937 ms | 13 MB + 800 KB | Accepted | Score: 4 | 显示更多 |
Testcase #13 | 11.952 ms | 13 MB + 800 KB | Accepted | Score: 4 | 显示更多 |
Testcase #14 | 11.95 ms | 13 MB + 800 KB | Accepted | Score: 4 | 显示更多 |
Testcase #15 | 11.935 ms | 13 MB + 800 KB | Accepted | Score: 4 | 显示更多 |
Testcase #16 | 11.932 ms | 13 MB + 800 KB | Accepted | Score: 4 | 显示更多 |
Testcase #17 | 12.013 ms | 13 MB + 816 KB | Accepted | Score: 4 | 显示更多 |
Testcase #18 | 12.003 ms | 13 MB + 820 KB | Accepted | Score: 4 | 显示更多 |
Testcase #19 | 12.006 ms | 13 MB + 820 KB | Accepted | Score: 4 | 显示更多 |
Testcase #20 | 12.009 ms | 13 MB + 820 KB | Accepted | Score: 4 | 显示更多 |
Testcase #21 | 48.349 ms | 18 MB + 64 KB | Accepted | Score: 4 | 显示更多 |
Testcase #22 | 58.736 ms | 18 MB + 648 KB | Accepted | Score: 4 | 显示更多 |
Testcase #23 | 73.303 ms | 19 MB + 600 KB | Accepted | Score: 4 | 显示更多 |
Testcase #24 | 75.565 ms | 20 MB + 552 KB | Accepted | Score: 4 | 显示更多 |
Testcase #25 | 75.166 ms | 20 MB + 944 KB | Accepted | Score: 4 | 显示更多 |