#include #include #include using namespace std; #include #include using mint = atcoder::modint998244353; struct S { mint sum0, sum1, sum2, sum3, sum4; }; S op(S l, S r) { return {l.sum0 + r.sum0, l.sum1 + r.sum1, l.sum2 + r.sum2, l.sum3 + r.sum3, l.sum4 + r.sum4}; } S e() { return {0, 0, 0, 0, 0}; } using F = pair; S mp(F f, S x) { if (!f.first) return x; auto &v = f.second; return {x.sum0, x.sum0 * v, x.sum0 * v * v, x.sum0 * v * v * v, x.sum0 * v * v * v * v}; } F composition(F fnew, F gold) { if (fnew.first) return fnew; return gold; } F id() { return {false, 0}; } template std::istream &operator>>(std::istream &is, atcoder::static_modint &x) { long long t; return is >> t, x = t, is; } template std::ostream &operator<<(std::ostream &os, const atcoder::static_modint &x) { return os << x.val(); } int main() { cin.tie(nullptr), ios::sync_with_stdio(false); int N; cin >> N; vector A(N); for (auto &x : A) cin >> x; vector init; for (auto x : A) { init.push_back({1, x, x * x, x * x * x, x * x * x * x}); } atcoder::lazy_segtree tree(init); int Q; cin >> Q; while (Q--) { int type; int u, v, w; cin >> type >> u >> v >> w; vector> ranges; if (u > v) swap(u, v); if (u < w and w < v) { ranges.emplace_back(u - 1, v); } else { ranges.emplace_back(0, u), ranges.emplace_back(v - 1, N); } if (type == 0) { mint b; cin >> b; for (auto [l, r] : ranges) tree.apply(l, r, {true, b}); } else { auto ret = e(); for (auto [l, r] : ranges) ret = op(ret, tree.prod(l, r)); const mint mu = ret.sum1 / ret.sum0; if (type == 1) { cout << "0\n"; } else if (type == 2) { cout << (ret.sum2 - 2 * ret.sum1 * mu + ret.sum0 * mu * mu) / ret.sum0 << '\n'; } else if (type == 3) { cout << (ret.sum3 - 3 * ret.sum2 * mu + 3 * ret.sum1 * mu * mu - ret.sum0 * mu * mu * mu) / ret.sum0 << '\n'; } else if (type == 4) { cout << (ret.sum4 - 4 * ret.sum3 * mu + 6 * ret.sum2 * mu * mu - 4 * ret.sum1 * mu * mu * mu + ret.sum0 * mu * mu * mu * mu) / ret.sum0 << '\n'; } } } }