#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
const ll mod = 998244353;
const int maxn = 5e5+5;
ll sum[maxn<<2];
ll mul[maxn<<2];
ll add[maxn<<2];
void pull(int x) {
    sum[x] = (sum[x<<1] + sum[x<<1|1]) % mod;
}


void push(int x,int l,int r,int mid) {
    if (mul[x] != -1) {
        if (~mul[x<<1]) {
            mul[x<<1] *= mul[x];
            mul[x<<1] %= mod;
        }
        else {
            mul[x<<1] = mul[x];
        }
        sum[x<<1] *= mul[x];
        sum[x<<1] %= mod;
        if (~add[x<<1]) {
            add[x<<1] *= mul[x];
            add[x<<1] %= mod;
        }
        if (~mul[x<<1|1]) {
            mul[x<<1|1] *= mul[x];
            mul[x<<1|1] %= mod;
        }
        else {
            mul[x<<1|1] = mul[x];
        }
        sum[x<<1|1] *= mul[x];
        sum[x<<1|1] %= mod;
        if (~add[x<<1|1]) {
            add[x<<1|1] *= mul[x];
            add[x<<1|1] %= mod;
        }
        mul[x] = -1;
    }
    if (add[x] != -1) {
        if (!(~add[x<<1])) {
            add[x<<1] = add[x];
        }
        else {
            add[x<<1] += add[x];
            add[x<<1] %= mod;
        }
        sum[x<<1] += (mid-l+1) * add[x] % mod;
        sum[x<<1] %= mod;
        if (!(~add[x<<1|1])) {
            add[x<<1|1] = add[x];
        }
        else {
            add[x<<1|1] += add[x];
            add[x<<1|1] %= mod;
        }
        sum[x<<1|1] += (r - mid) * add[x] % mod;
        sum[x<<1|1] %= mod;
        add[x] = -1;
    }
}
void update(int x,int l,int r,int ql,int qr,int ad,int mu) {
    if (ql <= l && qr >= r) {
        sum[x] *= mu;
        sum[x] %= mod;
        sum[x] += (ll)(r - l + 1) * ad;
        sum[x] %= mod;
        if (mul[x] == -1) {
            mul[x] = mu;
        }
        else {
            mul[x] *= mu;
            mul[x] %= mod;
        }
        if (add[x] != -1) {
            add[x] *= mu;
            add[x] %= mod;
        }
        if (add[x] == -1) {
            add[x] = ad;
        }
        else {
            add[x] += ad;
            add[x] %= mod;
        }
        return;
    }
    int mid = (l + r) >> 1;
    push(x,l,r,mid);
    if (ql <= mid) {
        update(x<<1,l,mid,ql,qr,ad,mu);
    }
    if (qr > mid) {
        update(x<<1|1,mid+1,r,ql,qr,ad,mu);
    }
    pull(x);
}
ll query(int x,int l,int r,int ql,int qr) {
    if (ql <= l && qr >= r) {
        return sum[x];
    }
    int mid = (l + r) >> 1;
    push(x,l,r,mid);
    if (qr <= mid) {
        return query(x<<1,l,mid,ql,qr);
    }
    if (ql > mid) {
        return query(x<<1|1,mid+1,r,ql,qr);
    }
    return (query(x<<1,l,mid,ql,qr) + query(x<<1|1,mid+1,r,ql,qr)) % mod;
}
void build(int x,int l,int r) {
    if (l == r) {
        cin >> sum[x];
        return;
    }
    int mid = (l + r) >> 1;
    build(x<<1,l,mid);
    build(x<<1|1,mid+1,r);
    pull(x);
}
void solve() {
    int n, q;
    cin >> n >> q;
    memset(add, -1, sizeof(add));
    memset(mul,-1, sizeof(mul));
    build(1,1,n);
    while (q--) {
        int op,l,r;
        cin >> op >> l >> r;
        l++;
        if (op == 0) {
            int a, b;
            cin >> a >> b;
            update(1,1,n,l,r,b,a);
        }
        else {
            cout << query(1,1,n,l,r) << '\n';
        }
    }
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int c = 0;
    int t;
    if (!c) {
        t = 1;
    }
    else {
        cin >> t;
    }
    while (t--) {
        solve();
    }
    
}


Measured memory_bytes: 43036