#include <bits/stdc++.h>

#include <atcoder/all>

#define DEF_LAZYSEGTREE(name, T, op, e, F, mapping, composition)                             \
  namespace name {                                                                           \
  struct _T {                                                                                \
    T value;                                                                                 \
    int left, right, size;                                                                   \
    inline _T(const T& value, int left, int right, int size)                                 \
        : value(value), left(left), right(right), size(size) {}                              \
    inline _T(const T& value, int left = 0, int right = 1)                                   \
        : _T(value, left, right, right - left) {}                                            \
    inline _T() : _T((e), -1, -1, 0) {}                                                      \
  };                                                                                         \
  inline _T _op(_T _a, _T _b) {                                                              \
    const auto &a = _a.value, &b = _b.value;                                                 \
    int newLeft = (_a.size > 0 ? _a : _b).left;                                              \
    int newRight = (_b.size > 0 ? _b : _a).right;                                            \
    int newSize = _a.size + _b.size;                                                         \
    return _T((op), newLeft, newRight, newSize);                                             \
  }                                                                                          \
  inline _T _e() { return _T(); }                                                            \
  struct _F {                                                                                \
    F value;                                                                                 \
    bool enabled;                                                                            \
    inline _F(const F& value, bool enabled = true)                                           \
        : value(value), enabled(enabled) {}                                                  \
    inline _F() : _F(F(), false) {}                                                          \
  };                                                                                         \
  inline _T _mapping(_F _f, _T _a) {                                                         \
    if (!_f.enabled) return _a;                                                              \
    const auto& f = _f.value;                                                                \
    const auto& a = _a.value;                                                                \
    int l = _a.left, r = _a.right, s = _a.size;                                              \
    return _T((mapping), _a.left, _a.right, _a.size);                                        \
  }                                                                                          \
  inline _F _composition(_F _f, _F _g) {                                                     \
    if (!_f.enabled) return _g;                                                              \
    if (!_g.enabled) return _f;                                                              \
    const auto &f = _f.value, &g = _g.value;                                                 \
    return _F((composition), true);                                                          \
  }                                                                                          \
  inline _F _id() { return _F(); }                                                           \
  using type = typename atcoder::lazy_segtree<_T, _op, _e, _F, _mapping, _composition, _id>; \
  inline type generate(int n) {                                                              \
    std::vector<_T> _v(n);                                                                   \
    for (int i = 0; i < n; ++i) _v[i] = _T(e, i, i + 1, 1);                                  \
    return type(std::move(_v));                                                              \
  }                                                                                          \
  inline type generate(std::vector<T> v) {                                                   \
    const int n = v.size();                                                                  \
    std::vector<_T> _v(n);                                                                   \
    for (int i = 0; i < n; ++i) _v[i] = _T(v[i], i, i + 1, 1);                               \
    return type(std::move(_v));                                                              \
  }                                                                                          \
  }

// #LIB#

using namespace std;
using namespace atcoder;
using ll = long long;
#define double long double
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define repr(i, a, b) for (auto i = (a); i < (b); ++i)
#define itr(x, c) for (auto&& x : (c))
#define updatemax(t, v) ((t) = std::max((t), (v)))
#define updatemin(t, v) ((t) = std::min((t), (v)))
#ifdef ONLINE_JUDGE
#define endl _endl
const char _endl = (cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout.precision(16), '\n');
#endif

using mint = static_modint<998244353>;
using pmm = pair<mint, mint>;

DEF_LAZYSEGTREE(seg, mint, a + b, 0, pmm, f.first* a + f.second * s, (pmm(f.first * g.first, f.first* g.second + f.second)))

int main() {
  ll n, q;
  cin >> n >> q;
  vector<mint> a(n);
  rep(i, n) {
    ll x;
    cin >> x;
    a[i] = x;
  }
  auto st = seg::generate(a);
  rep(i, q) {
    ll qk;
    cin >> qk;
    if (qk == 0) {
      ll l, r, b, c;
      cin >> l >> r >> b >> c;
      st.apply(l, r, pmm(b, c));
    } else if (qk == 1) {
      ll l, r;
      cin >> l >> r;
      cout << st.prod(l, r).value.val() << endl;
    }
  }
}


Measured memory_bytes: 37516