#include #include using namespace std; #include using mint = atcoder::modint998244353; #include struct S { mint v0, v1; int n; }; S op(S l, S r) { return {l.v0 + r.v0, l.v1 + r.v1, l.n + r.n}; } S e() { return {0, 0, 0}; } struct F { mint nsame, ndiff; }; S mapping(F f, S x) { return {x.v0 * f.nsame + x.v1 * f.ndiff, x.v1 * f.nsame + x.v0 * f.ndiff, x.n}; } F composition(F fnew, F gold) { return {fnew.nsame * gold.nsame + fnew.ndiff * gold.ndiff, fnew.nsame * gold.ndiff + fnew.ndiff * gold.nsame}; } F id() { return {1, 0}; } int main() { cin.tie(nullptr), ios::sync_with_stdio(false); int N, M; cin >> N >> M; mint ret = 0; vector segtree_init(N + M, e()); vector seen_last(N); for (int i = 0; i < N; ++i) { segtree_init[i] = S{1, 0, 1}; seen_last[N - 1 - i] = i; } atcoder::lazy_segtree tree(segtree_init); int nempty = 0; const F f1{mint(N - 1) / N, mint(1) / N}; for (int t = 0; t < M; ++t) { int a; cin >> a; --a; if (a < 0) { ++nempty; tree.apply(0, N + t, f1); } else { int l = seen_last[a], r = N + t; auto p = tree.prod(l + 1, r); ret += tree.get(l).v1 * (N - 1 - p.n) + p.v0; tree.set(l, e()); tree.set(r, S{1, 0, 1}); seen_last[a] = r; } } cout << (ret + M + mint(N - 1) / 2 * nempty).val() << '\n'; }