#include<iostream> #include<algorithm> #define maxn 300010 #define lowbit(i) ((i) & (-i)) #define ll long long usingnamespacestd;
constint p = 998244353; ll pow_mod(ll x, ll n){ ll s = 1; for (; n; n >>= 1, x = x * x % p) if (n & 1) s = s * x % p; return s; }
inlineintadd(int x, int y){ return (x += y) >= p ? x - p : x; }
int n, m, a[maxn];
int b[maxn], cnt; voidinit_hash(){ for (int i = 1; i <= n; ++i) b[i] = a[i]; sort(b + 1, b + n + 1); cnt = unique(b + 1, b + n + 1) - b - 1; for (int i = 1; i <= n; ++i) a[i] = lower_bound(b + 1, b + cnt + 1, a[i]) - b; }
structFenwick { int Bit[maxn]; voidadd(int i, int v){ while (i <= cnt) Bit[i] = ::add(Bit[i], v), i += lowbit(i); } intget_sum(int i){ int s = 0; while (i) s = ::add(s, Bit[i]), i -= lowbit(i); return s; } voidclear(){ for (int i = 1; i <= cnt; ++i) Bit[i] = 0; } } B;
ll fac[maxn * 2], inv[maxn * 2]; voidinit_C(int n){ fac[0] = 1; for (int i = 1; i <= n; ++i) fac[i] = fac[i - 1] * i % p; inv[n] = pow_mod(fac[n], p - 2); for (int i = n - 1; ~i; --i) inv[i] = inv[i + 1] * (i + 1) % p; }
ll C(int n, int m){ return n < m ? 0 : fac[n] * inv[m] % p * inv[n - m] % p; }
voidwork(){ cin >> n >> m; ++m; ll ans = 0; for (int i = 1; i <= n; ++i) cin >> a[i]; init_hash(); B.clear(); for (int i = n; i; --i) { B.add(a[i], C(n - i + m - 1, m - 1)); ans = (ans + B.get_sum(a[i] - 1) * C(i - 1 + m - 1, m - 1)) % p; } cout << ans << "\n"; }