#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1000000007;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> PlP;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;
using namespace atcoder;

const int mod = 998244353;
class mint {
public:
    long long x;
    mint(long long x=0) : x((x%mod+mod)%mod) {}
    mint operator-() const { 
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }
 
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};
 
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} comb(200010);

struct S {
    mint a;
    int size;
};

struct F {
    mint a, b;
};

S op(S l, S r) { return S{l.a + r.a, l.size + r.size}; }

S e() { return S{0, 0}; }

S mapping(F l, S r) { return S{r.a * l.a + mint(r.size) * l.b, r.size}; }

F composition(F l, F r) { return F{r.a * l.a, r.b * l.a + l.b}; }

F id() { return F{1, 0}; }

int main(){
    ll N,Q;
    cin >> N >> Q;
    vector<S> a(N);
    ll tmp;
    rep(i,N){
        cin >> tmp;
        a[i] = S{mint(tmp),1};
    }
    lazy_segtree<S, op, e, F, mapping, composition, id> seg(a);
    vector<ll> t(Q), l(Q), r(Q), b(Q), c(Q);
    rep(i,Q){
        cin >> t[i];
        if(t[i] == 0){
            cin >> l[i] >> r[i] >> b[i] >> c[i]; 
        }else{
            cin >> l[i] >> r[i]; 
        }
    }
    //cout << "aaaaaaa" << endl;
    rep(i,Q){
        //cin >> t[i];
        if(t[i] == 0){
            seg.apply(l[i], r[i], F{mint(b[i]), mint(c[i])});
        }else{
            //cout << "bbbb" << endl;
            cout << seg.prod(l[i],r[i]).a << endl;
            //cout << "vvvvvvvvvvvvv" << endl;
        }
    }
    /*lazy_segtree<S, op, e, F, mapping, composition, id> seg(int n);
    rep(i,N){
        cin >> A[i];
        seg.set(i,A[i]);
    }
    vector<int> a(Q),b(Q),c(Q);
    rep(i,Q){
        cin >> a[i] >> b[i] >> c[i];
    }
    int t,x,v;
    rep(i,Q){
        t = a[i];
        x = b[i];
        v = c[i];
        if(t==1){
            x--;
            seg.set(x,v);
        }else if(t==2){
            x--;
            cout << seg.prod(x,v) << endl;
        }else{
            target = v;
            x--;
            cout << seg.max_right<f>(x) + 1 << endl;
        }
    }*/
}

Measured memory_bytes: 58424