#include #include #include #include using namespace std; using ll = long long; using ull = unsigned long long; #define rep(i,n) for(int i=0; i<(n); i++) using mll = atcoder::static_modint<998244353>; template< class S, S(*op)(S a, S b), S(*e)(), class F, S(*mapping)(F a, S b), F(*composition)(F a, F b), F(*id)() > struct lazy_segtree{ private: struct Node{ S v; F r; }; int N,logN; vector V; void mapF(int i,F f){ V[i].v = mapping(f,V[i].v); V[i].r = composition(f,V[i].r); } void merge(int i){ V[i].v = mapping(V[i].r,op(V[i*2].v,V[i*2+1].v)); } void spread(int i){ mapF(i*2,V[i].r); mapF(i*2+1,V[i].r); V[i].r=id(); } public: lazy_segtree(int n){ N=1; logN=0; while(N A) : lazy_segtree(A.size()){ rep(i,A.size()) V[N+i].v=A[i]; for(int i=N-1; i>=1; i--) merge(i); } void set(int p,S v){ p+=N; for(int d=logN; d>=1; d--) spread(p>>d); V[p].v=v; for(int d=1; d<=logN; d++) merge(p>>d); } S get(int p){ p+=N; for(int d=logN; d>=1; d--) spread(p>>d); return V[p].v; } S prod(int l,int r){ l+=N; r+=N; for(int d=logN; d>=1; d--){ spread(l>>d); spread((r-1)>>d); } S ql=e(), qr=e(); while(l=1; d--) spread(p>>d); mapF(p,f); for(int d=1; d<=logN; d++) merge(p>>d); } void apply(int l,int r,F f){ l+=N; r+=N; for(int d=logN; d>=1; d--){ spread(l>>d); spread((r-1)>>d); } int lp=l, rp=r; while(l>d); merge((rp-1)>>d); } } }; struct S { mll G[5]; }; S op(S l, S r) { S res; rep(i,5) res.G[i] = l.G[i] + r.G[i]; return res; } S e() { return { {0,0,0,0,0} }; } struct F { int upd; }; S mapping(F f, S a) { if(f.upd != -1){ rep(t,4) a.G[t+1] = a.G[t] * f.upd; } return a; } F composition(F f, F g) { return (f.upd == -1) ? g : f; } F id() { return { -1 }; } using RQ = lazy_segtree; int N; vector A; RQ G(0); int Q; int main(){ cin >> N; A.resize(N); rep(i,N){ int a; cin >> a; A[i].G[0] = 1; rep(t,4) A[i].G[t+1] = A[i].G[t] * a; } G = RQ(A); cin >> Q; rep(q,Q){ int t,u,v,w; cin >> t >> u >> v >> w; u--; v--; w--; if(u > v) swap(u,v); int l1, r1, l2, r2; if(u <= w && w <= v){ l1=u; r1=v+1; l2=0; r2=0; } else{ l1=v; r1=N; l2=0; r2=u+1; } if(t == 0){ int b; cin >> b; G.apply(l1,r1,{b}); G.apply(l2,r2,{b}); } else{ S x = op( G.prod(l1,r1) , G.prod(l2,r2) ); vector coe; mll M = x.G[1] * x.G[0].inv(); if(t == 1) coe = {-M,1,0,0,0}; if(t == 2) coe = {M*M,-M*2,1,0,0}; if(t == 3) coe = {-M*M*M,M*M*3,-M*3,1,0}; if(t == 4) coe = {M*M*M*M,-M*M*M*4,M*M*6,-M*4,1}; mll ans = 0; rep(t,5) ans += x.G[t] * coe[t]; ans /= x.G[0]; cout << ans.val() << "\n"; } } return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ ios::sync_with_stdio(false); cin.tie(nullptr); } } ios_do_not_sync_inst;