#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define MD (998244353U)
void*wmem;
char memarr[96000000];
template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){
  static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
  (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] );
  (*arr)=(T*)(*mem);
  (*mem)=((*arr)+x);
}
struct Modint{
  unsigned val;
  Modint(){
    val=0;
  }
  Modint(int a){
    val = ord(a);
  }
  Modint(unsigned a){
    val = ord(a);
  }
  Modint(long long a){
    val = ord(a);
  }
  Modint(unsigned long long a){
    val = ord(a);
  }
  inline unsigned ord(unsigned a){
    return a%MD;
  }
  inline unsigned ord(int a){
    a %= (int)MD;
    if(a < 0){
      a += MD;
    }
    return a;
  }
  inline unsigned ord(unsigned long long a){
    return a%MD;
  }
  inline unsigned ord(long long a){
    a %= (int)MD;
    if(a < 0){
      a += MD;
    }
    return a;
  }
  inline unsigned get(){
    return val;
  }
  inline Modint &operator+=(Modint a){
    val += a.val;
    if(val >= MD){
      val -= MD;
    }
    return *this;
  }
  inline Modint &operator-=(Modint a){
    if(val < a.val){
      val = val + MD - a.val;
    }
    else{
      val -= a.val;
    }
    return *this;
  }
  inline Modint &operator*=(Modint a){
    val = ((unsigned long long)val*a.val)%MD;
    return *this;
  }
  inline Modint &operator/=(Modint a){
    return *this *= a.inverse();
  }
  inline Modint operator+(Modint a){
    return Modint(*this)+=a;
  }
  inline Modint operator-(Modint a){
    return Modint(*this)-=a;
  }
  inline Modint operator*(Modint a){
    return Modint(*this)*=a;
  }
  inline Modint operator/(Modint a){
    return Modint(*this)/=a;
  }
  inline Modint operator+(int a){
    return Modint(*this)+=Modint(a);
  }
  inline Modint operator-(int a){
    return Modint(*this)-=Modint(a);
  }
  inline Modint operator*(int a){
    return Modint(*this)*=Modint(a);
  }
  inline Modint operator/(int a){
    return Modint(*this)/=Modint(a);
  }
  inline Modint operator+(long long a){
    return Modint(*this)+=Modint(a);
  }
  inline Modint operator-(long long a){
    return Modint(*this)-=Modint(a);
  }
  inline Modint operator*(long long a){
    return Modint(*this)*=Modint(a);
  }
  inline Modint operator/(long long a){
    return Modint(*this)/=Modint(a);
  }
  inline Modint operator-(void){
    Modint res;
    if(val){
      res.val=MD-val;
    }
    else{
      res.val=0;
    }
    return res;
  }
  inline operator bool(void){
    return val!=0;
  }
  inline operator int(void){
    return get();
  }
  inline operator long long(void){
    return get();
  }
  inline Modint inverse(){
    int a = val;
    int b = MD;
    int u = 1;
    int v = 0;
    int t;
    Modint res;
    while(b){
      t = a / b;
      a -= t * b;
      swap(a, b);
      u -= t * v;
      swap(u, v);
    }
    if(u < 0){
      u += MD;
    }
    res.val = u;
    return res;
  }
  inline Modint pw(unsigned long long b){
    Modint a(*this);
    Modint res;
    res.val = 1;
    while(b){
      if(b&1){
        res *= a;
      }
      b >>= 1;
      a *= a;
    }
    return res;
  }
  inline bool operator==(int a){
    return ord(a)==val;
  }
  inline bool operator!=(int a){
    return ord(a)!=val;
  }
}
;
inline Modint operator+(int a, Modint b){
  return Modint(a)+=b;
}
inline Modint operator-(int a, Modint b){
  return Modint(a)-=b;
}
inline Modint operator*(int a, Modint b){
  return Modint(a)*=b;
}
inline Modint operator/(int a, Modint b){
  return Modint(a)/=b;
}
inline Modint operator+(long long a, Modint b){
  return Modint(a)+=b;
}
inline Modint operator-(long long a, Modint b){
  return Modint(a)-=b;
}
inline Modint operator*(long long a, Modint b){
  return Modint(a)*=b;
}
inline Modint operator/(long long a, Modint b){
  return Modint(a)/=b;
}
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(Modint &x){
  int i;
  rd(i);
  x=i;
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(unsigned x){
  int s=0;
  char f[10];
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(unsigned long long x){
  int s=0;
  char f[21];
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(Modint x){
  int i;
  i = (int)x;
  wt_L(i);
}
int WRITER_DOUBLE_DIGIT = 15;
inline int writerDigit_double(){
  return WRITER_DOUBLE_DIGIT;
}
inline void writerDigit_double(int d){
  WRITER_DOUBLE_DIGIT = d;
}
inline void wt_L(double x){
  const int d = WRITER_DOUBLE_DIGIT;
  int k;
  int r;
  double v;
  if(x!=x || (x==x+1 && x==2*x)){
    my_putchar_unlocked('E');
    my_putchar_unlocked('r');
    my_putchar_unlocked('r');
    return;
  }
  if(x < 0){
    my_putchar_unlocked('-');
    x = -x;
  }
  x += 0.5 * pow(0.1, d);
  r = 0;
  v = 1;
  while(x >= 10*v){
    v *= 10;
    r++;
  }
  while(r >= 0){
    r--;
    k = floor(x / v);
    if(k >= 10){
      k = 9;
    }
    if(k <= -1){
      k = 0;
    }
    x -= k * v;
    v *= 0.1;
    my_putchar_unlocked(k + '0');
  }
  if(d > 0){
    my_putchar_unlocked('.');
    v = 1;
    for(r=(0);r<(d);r++){
      v *= 0.1;
      k = floor(x / v);
      if(k >= 10){
        k = 9;
      }
      if(k <= -1){
        k = 0;
      }
      x -= k * v;
      my_putchar_unlocked(k + '0');
    }
  }
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    my_putchar_unlocked(c[i]);
  }
}
inline void wt_L(string &x){
  int i=0;
  for(i=0;x[i]!='\0';i++){
    my_putchar_unlocked(x[i]);
  }
}
template<class SVAL, class SFUN> struct segtree_rg{
  int N;
  int logN;
  SVAL*val;
  SFUN*fun;
  void malloc(int maxN, int once = 0){
    int i;
    for(i=1;i<maxN;i*=2){
      ;
    }
    val = new SVAL[2*i];
    fun = new SFUN[i];
    if(once){
      setN(maxN);
    }
  }
  void walloc(int maxN, int once = 0, void **mem = &wmem){
    int i;
    for(i=1;i<maxN;i*=2){
      ;
    }
    walloc1d(&val, 2*i, mem);
    walloc1d(&fun, i, mem);
    if(once){
      setN(maxN);
    }
  }
  void free(void){
    delete [] val;
    delete [] fun;
  }
  SVAL& operator[](int i){
    return val[N+i];
  }
  void setN(int n, int zerofill = 1, int dobuild = 1){
    int i;
    for(i=1,logN=0;i<n;i*=2,logN++){
      ;
    }
    N = i;
    if(dobuild){
      build();
    }
  }
  void build(void){
    int i;
    for(i=N-1;i;i--){
      segtree_rg_func(val[i], val[2*i], val[2*i+1]);
    }
    int aWpYLTGo = N;
    for(i=(1);i<(aWpYLTGo);i++){
      segtree_rg_id(fun[i]);
    }
  }
  inline void push_one(int a){
    if(2*a < N){
      segtree_rg_func(fun[2*a], fun[a], fun[2*a]);
    }
    segtree_rg_func(val[2*a], fun[a], val[2*a]);
    if(2*a+1 < N){
      segtree_rg_func(fun[2*a+1], fun[a], fun[2*a+1]);
    }
    segtree_rg_func(val[2*a+1], fun[a], val[2*a+1]);
    segtree_rg_id(fun[a]);
  }
  inline void push(int a){
    int i;
    for(i=logN;i;i--){
      push_one(a>>i);
    }
  }
  inline void build(int a){
    while(a > 1){
      a /= 2;
      segtree_rg_func(val[a], val[2*a], val[2*a+1]);
      segtree_rg_func(val[a], fun[a], val[a]);
    }
  }
  inline void change(int a, int b, SFUN f){
    int aa;
    int bb;
    if(a >= b){
      return;
    }
    aa = (a += N);
    bb = (b += N);
    push(a);
    push(b-1);
    if(a%2){
      segtree_rg_func(val[a], f, val[a]);
      a++;
    }
    if(b%2){
      b--;
      segtree_rg_func(val[b], f, val[b]);
    }
    a /= 2;
    b /= 2;
    while(a < b){
      if(a%2){
        segtree_rg_func(val[a], f, val[a]);
        segtree_rg_func(fun[a], f, fun[a]);
        a++;
      }
      if(b%2){
        b--;
        segtree_rg_func(val[b], f, val[b]);
        segtree_rg_func(fun[b], f, fun[b]);
      }
      a /= 2;
      b /= 2;
    }
    build(aa);
    build(bb-1);
  }
  inline SVAL get(int a, int b){
    SVAL res;
    SVAL tmp;
    int fga = 0;
    int fgb = 0;
    a += N;
    b += N;
    push(a);
    push(b-1);
    while(a < b){
      if(a%2){
        if(fga){
          segtree_rg_func(res, res, val[a]);
        }
        else{
          res = val[a];
          fga = 1;
        }
        a++;
      }
      if(b%2){
        b--;
        if(fgb){
          segtree_rg_func(tmp, val[b], tmp);
        }
        else{
          tmp = val[b];
          fgb = 1;
        }
      }
      a /= 2;
      b /= 2;
    }
    if(fga==1 && fgb==0){
      return res;
    }
    if(fga==0 && fgb==1){
      return tmp;
    }
    if(fga==1 && fgb==1){
      segtree_rg_func(res, res, tmp);
      return res;
    }
    return res;
  }
}
;
struct segval{
  Modint x;
  Modint s;
}
;
struct segfun{
  Modint a;
  Modint b;
}
;
void segtree_rg_id(segfun &res){
  res.a = 1;
  res.b = 0;
}
void segtree_rg_func(segval &res, segfun f, segval a){
  res.x = a.x * f.a + a.s * f.b;
}
void segtree_rg_func(segval &res, segval a, segval b){
  res.x = a.x + b.x;
  res.s = a.s + b.s;
}
void segtree_rg_func(segfun &res, segfun f, segfun g){
  res.a = f.a * g.a;
  res.b = f.a * g.b + f.b;
}
int N;
int Q;
int A[500000];
int T;
int L;
int R;
int main(){
  int RZTsC2BF, i;
  wmem = memarr;
  segtree_rg<segval, segfun> t;
  segfun f;
  rd(N);
  rd(Q);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  t.malloc(N);
  t.setN(N, 0, 0);
  for(i=(0);i<(N);i++){
    t[i].x = A[i];
    t[i].s = 1;
  }
  t.build();
  for(RZTsC2BF=(0);RZTsC2BF<(Q);RZTsC2BF++){
    rd(T);
    rd(L);
    rd(R);
    if(T==0){
      rd(f.a);
      rd(f.b);
      t.change(L, R, f);
    }
    else{
      wt_L(t.get(L, R).x);
      wt_L('\n');
    }
  }
  return 0;
}
// cLay varsion 20200916-1

// --- original code ---
// #define MD 998244353
// 
// struct segval{ Modint x, s; };
// struct segfun{ Modint a, b; };
// 
// void segtree_rg_id(segfun &res){
//   res.a = 1;
//   res.b = 0;
// }
// 
// void segtree_rg_func(segval &res, segfun f, segval a){
//   res.x = a.x * f.a + a.s * f.b;
// }
// 
// void segtree_rg_func(segval &res, segval a, segval b){
//   res.x = a.x + b.x;
//   res.s = a.s + b.s;
// }
// 
// void segtree_rg_func(segfun &res, segfun f, segfun g){
//   res.a = f.a * g.a;
//   res.b = f.a * g.b + f.b;
// }
// 
// int N, Q, A[5d5], T, L, R;
// {
//   segtree_rg<segval, segfun> t;
//   segfun f;
// 
//   rd(N,Q,A(N));
//   t.malloc(N);
//   t.setN(N, 0, 0);
//   rep(i,N){
//     t[i].x = A[i];
//     t[i].s = 1;
//   }
//   t.build();
//   rep(Q){
//     rd(T, L, R);
//     if(T==0){
//       rd(f.a, f.b);
//       t.change(L, R, f);
//     } else {
//       wt(t.get(L, R).x);
//     }
//   }
// }


Measured memory_bytes: 19892