#include using namespace std; #include int pt_op(int a, int b) { return min(a, b); } int pt_e() { return 1e9; } struct pt_node { // typ: // 0: one // 1: inc // 2: dec // 3: prime int par, typ, l, r; }; // assume p in [0, n) with length n // ref: https://judge.yosupo.jp/submission/252918 vector permutation_tree(vector p) { struct left_pfix { int x, mx, mn; }; int n = (int)p.size(); assert(n >= 1); vector pinv(n); for(int i=0; i seg(pinv); vector st; vector candi(n+1, vector>(0)); for(int r=1; r<=n; r++) { left_pfix now = {r-1, p[r-1], p[r-1]}; while (!st.empty()) { st.back().mx = max(st.back().mx, now.mx); st.back().mn = min(st.back().mn, now.mn); auto g = st.back(); if (g.mx-g.mn+1 == r-g.x) { candi[r-g.x].push_back(pair(g.x, r)); now = g; st.pop_back(); }else if(seg.prod(g.mn,g.mx+1) < g.x){ st.pop_back(); if (st.empty()) continue; auto& h = st.back(); h.mx = max(h.mx, g.mx); h.mn = min(h.mn, g.mn); }else{ break; } } st.push_back(now); } vector ret; vector node_id(n); vector node_jump(n+1); for (int i=0; i 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--) #define all(v) v.begin(), v.end() 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; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n >> k; vector p(n); rep(i,0,n) { cin >> p[i]; p[i]--; } vector f = permutation_tree(p); int m = (int)f.size(); int root = -1; vector ikeru(m, vector(0)); rep(i,0,m) { if (f[i].par == -1) { root = i; }else{ ikeru[f[i].par].push_back(i); } } vector dp(m, vector(k+1)); auto dfs = [&](auto self, int i) -> void { sort(all(ikeru[i]), [&](int a, int b) { return f[a].l < f[b].l; }) ; for (int j: ikeru[i]) { self(self, j); } if (f[i].typ == 1 || f[i].typ == 2) { vector horyu(k+1); vector rui(k+1); horyu[0] = 1; dp[i][0] = 1; for (int j: ikeru[i]) { vector ndp(k+1); rep(x,0,k+1) rep(y,0,k+1-x) { ndp[x+y] += dp[i][x] * dp[j][y]; } rep(x,0,k) { ndp[x+1] += rui[x]; } rep(x,0,k+1) rui[x] += horyu[x]; horyu = ndp; swap(dp[i], ndp); } }else if(f[i].typ == 3){ dp[i][0] = 1; for (int j: ikeru[i]) { vector ndp(k+1); rep(x,0,k+1) rep(y,0,k+1-x) { ndp[x+y] += dp[i][x] * dp[j][y]; } swap(dp[i], ndp); } dp[i][1] += 1; }else{ dp[i][1] = 1; } }; dfs(dfs, root); rep(i,1,k+1) { cout << dp[root][i].val() << '\n'; } }