#include using namespace std; //* ATCODER #include using namespace atcoder; typedef modint998244353 mint; //*/ /* BOOST MULTIPRECISION #include using namespace boost::multiprecision; //*/ typedef long long ll; #define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++) #define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--) template bool chmin(T &a, const T &b) { if (a <= b) return false; a = b; return true; } template bool chmax(T &a, const T &b) { if (a >= b) return false; a = b; return true; } template T max(vector &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]); return ret; } template T min(vector &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]); return ret; } template T sum(vector &a){ T ret = 0; for (int i=0; i<(int)a.size(); i++) ret += a[i]; return ret; } //defmodfact const int COMinitMAX = 998244; mint fact[COMinitMAX+1], factinv[COMinitMAX+1]; void modfact(){ fact[0] = 1; for (int i=1; i<=COMinitMAX; i++){ fact[i] = fact[i-1] * i; } factinv[COMinitMAX] = fact[COMinitMAX].inv(); for (int i=COMinitMAX-1; i>=0; i--){ factinv[i] = factinv[i+1] * (i+1); } } mint binom(int a, int b){ if (a> n; vector a(n); int all_empty = 0; rep(i,0,n){ cin >> a[i]; a[i]--; all_empty += (a[i] < 0); } fenwick_tree fw(n); rep(i,0,n){ if (a[i] >= 0){ fw.add(a[i],1); } } int now_empty = 0; mint ans = 0; int nowmax = -1; rep(i,0,n){ if (a[i] < 0) { ans += fact[now_empty] * fact[all_empty - now_empty - 1] * ( binom(all_empty, now_empty+1) - binom(nowmax+1 - fw.sum(0, nowmax+1), now_empty+1) ); now_empty++; }else{ int freedom = a[i] - fw.sum(0, a[i]); if (chmax(nowmax, a[i])){ ans += binom(freedom, now_empty) * fact[now_empty] * fact[all_empty - now_empty]; } } } cout << ans.val() << '\n'; }