#include<iostream>
#include<vector>

namespace ate{
  template<int64_t p>
  struct F_p{
    using value_type = int64_t;
    static constexpr inline value_type get_mod(){return p;}

    value_type value;

    constexpr F_p():value(value_type{}){}
    template<class T>constexpr F_p(T v):value(static_cast<value_type>(v<0?v%p+p:v%p)){}
  // operator +, -, *, /, ^ 
    constexpr F_p operator + (const F_p& other)const{
      return F_p(*this) += other;
    }
    constexpr F_p operator - (const F_p& other)const{
      return F_p(*this) -= other;
    }
    constexpr F_p operator * (const F_p& other)const{
      return F_p(*this) *= other;
    }
    constexpr F_p operator / (const F_p& other)const{
      return F_p(*this) /= other;
    }
    template<class T> constexpr F_p operator ^ (const T other)const{
      return F_p(*this) ^= other;
    }
    constexpr F_p &operator += (const F_p& other){
      value+=other.value;
      if(value>p)value-=p;
      return *this;
    }
    constexpr F_p &operator -= (const F_p& other){
      value-=other.value;
      if(value<0)value+=p;
      return *this;
    }
    constexpr F_p &operator *= (const F_p& other){
      value*=other.value;
      if(value>p)value%=p;
      return *this;
    }
    constexpr F_p &operator /= (const F_p& other){
      value*=other.inverse();
      if(value>p)value%=p;
      return *this;
    }
    template<class T>
    constexpr F_p &operator ^= (const T n){
      value = mpow(n).value;
      return *this;
    }
  // ext_gcd,inverse,mpow 
    static constexpr value_type ext_gcd(value_type a,value_type b,value_type& x,value_type& y){
      if(b==0){x=1,y=0;return a;}
      value_type d=ext_gcd(b,a%b,y,x);
      y-=a/b*x;return d;
    }
    constexpr value_type inverse()const{
      value_type x,y;
      ext_gcd(value,p,x,y);
      return x<0?x%p+p:x%p;
    }
    template<class T>
    static constexpr value_type inverse(T val){
      value_type x,y;
      ext_gcd(val,p,x,y);
      return x<0?x%p+p:x%p;
    }
    template<class T>
    constexpr F_p mpow(T n)const{
      F_p res(1),vn(*this);
      while(n){
        if(n&1)res*=vn;
        vn*=vn;
        n>>=1;
      }
      return res;
    }
    template<class T,class U>
    static constexpr T mpow(T a,U b){
      F_p x(a);
      return static_cast<T>(x.mpow(b).value);
    }
  // operator iostream 
    constexpr friend std::istream &operator >> (std::istream& is,F_p& fp){
      is>>fp.value;
      return is;
    }constexpr friend std::ostream &operator << (std::ostream& os,const F_p& fp){
      os<<fp.value;
      return os;
    }
  //operator bool
    constexpr bool operator == (const F_p& other)const{
      return value == other.value;
    }
  };
}
using mint = ate::F_p<119<<23|1>;

template<class T,class U,class F,class G,class H>
struct lazy_segment_tree{
  std::vector<T> data;
  std::vector<U> lazy;
  int n,height;
  F merge;
  G mapping;
  H composition;
  T ti;
  U ui;
  lazy_segment_tree(){}
  lazy_segment_tree(std::vector<T>const& v,T ide1,U ide2,F f,G g,H h)
    :ti(ide1),ui(ide2),merge(f),mapping(g),composition(h)
  {
    int sz = std::size(v);
    n=1,height=0;
    while(n<sz)n<<=1,height++;
    data.resize(n<<1,ti);
    lazy.resize(n<<1,ui);
    for(int i=0;i<sz;++i)
      data[i+n] = v[i];
    for(int i=n;i-->0;)
      data[i] = merge(data[i<<1|0],data[i<<1|1]);
  }
  inline T reflect(int k){
    return lazy[k]==ui?data[k]:mapping(data[k],lazy[k]);
  }
  inline void evaluate(int k){
    if(lazy[k]==ui)return;
    if(k<n){
      lazy[k<<1|0] = composition(lazy[k<<1|0],lazy[k]);
      lazy[k<<1|1] = composition(lazy[k<<1|1],lazy[k]);
    }
    data[k] = reflect(k);
    lazy[k] = ui;
  }
  inline void propagate(int k){
    for(int i=height;i>=0;--i)evaluate(k>>i);
  }
  inline void recalc(int k){
    while(k>>=1)data[k] = merge(reflect(k<<1|0),reflect(k<<1|1));
  }
  void update(int a,int b,U v){
    a+=n;b+=n;propagate(a);propagate(b-1);
    for(int l=a,r=b;l<r;l>>=1,r>>=1){
      if(l&1)lazy[l] = composition(lazy[l],v),l++;
      if(r&1)--r,lazy[r] = composition(lazy[r],v);
    }
    recalc(a);recalc(b-1);
  }
  T fold(int a,int b){
    a+=n;b+=n;propagate(a),propagate(b-1);
    T lef_v(ti),rig_v(ti);
    for(int l=a,r=b;l<r;l>>=1,r>>=1){
      if(l&1)lef_v = merge(lef_v,reflect(l)),l++;
      if(r&1)--r,rig_v = merge(reflect(r),rig_v);
    }
    return merge(lef_v,rig_v);
  }
};
template<class T,class U,class F,class G,class H>
auto make_lseg(std::vector<T> v,T ide1,U ide2,F f,G g,H h){
  return lazy_segment_tree<T,U,F,G,H>(v,ide1,ide2,f,g,h);
}

void RMQandRUQ();
void RSQandRAQ();
void RMQandRAQ();
void RSQandRUQ();

void range_affine_range_sum();

signed main(){
  range_affine_range_sum();
}

void range_affine_range_sum(){
  using namespace std;
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  constexpr char newl = '\n';
  
  struct ushi{
    mint val;
    int sz;
    ushi():val(),sz(1){}
    ushi(mint v,int s):val(v),sz(s){}
  };
  struct tapu{
    mint a,b;
    tapu():a(1),b(){}
    tapu(mint aa,mint bb):a(aa),b(bb){}
    bool operator == (const tapu& other)const{
      return a==other.a and b==other.b;
    }
  };
  auto f = [](ushi lhs,ushi rhs){
    auto&[a,b]=lhs;auto&[c,d]=rhs;
    return ushi(a+c,b+d);
  };
  auto g = [](ushi lhs,tapu rhs){
    auto&[val,sz]=lhs;auto&[a,b]=rhs;
    return ushi(val*a+b*sz,sz);
  };
  auto h = [](tapu lhs,tapu rhs){
    auto&[a,b]=lhs;auto&[c,d]=rhs;
    return tapu(a*c,b*c+d);
  };
  int n,q;
  cin>>n>>q;
  vector<ushi> a(n);
  for(int i=0;i<n;++i)cin>>a[i].val;
  auto seg = make_lseg<ushi,tapu>(a,ushi(),tapu(),f,g,h);
  while(q--){
    int com;cin>>com;
    if(com==0){
      int l,r,b,c;cin>>l>>r>>b>>c;
      seg.update(l,r,{b,c});
    }
    if(com==1){
      int l,r;cin>>l>>r;
      ushi res = seg.fold(l,r);
      cout<<res.val<<newl;
    }
  }
}

void RMQandRUQ(){
  using namespace std;
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  constexpr char newl = '\n';
  constexpr int inf = (int)((1ll<<31)-1);

  int n,q;
  cin>>n>>q;
  vector<int> a(n,inf);
  auto f = [](int a,int b){return a>b?b:a;};
  auto g = [](int a,int b){return b;};
  auto h = [](int a,int b){return b;};
  auto seg = make_lseg<int,int>(a,inf,-inf,f,g,h);
  while(q--){
    int com;cin>>com;
    if(com==0){
      int s,t,x;cin>>s>>t>>x;
      seg.update(s,t+1,x);
    }
    if(com==1){
      int s,t;cin>>s>>t;
      int res = seg.fold(s,t+1);
      cout<<res<<newl;
    }
  }
}
void RSQandRAQ(){
  using namespace std;
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  constexpr char newl = '\n';
  using i64=int64_t;
  struct ushi{
    i64 val;int sz;
    ushi():val(),sz(1){}
    ushi(i64 v,int s):val(v),sz(s){}
  };
  auto f = [](ushi a,ushi b){return ushi(a.val+b.val,a.sz+b.sz);};
  auto g = [](ushi a,i64 b){return ushi(a.val+a.sz*b,a.sz);};
  auto h = [](i64 a,i64 b){return a+b;};
  ushi ti = ushi(0,1);
  i64 ui = 0;
  int n,q;
  cin>>n>>q;
  vector<ushi> a(n);
  auto seg = make_lseg<ushi,i64>(a,ti,ui,f,g,h);
  while(q--){
    int com;cin>>com;
    if(com==0){
      int s,t,x;cin>>s>>t>>x;s--;t--;
      seg.update(s,t+1,x);
    }
    if(com==1){
      int s,t;cin>>s>>t;s--;t--;
      ushi res = seg.fold(s,t+1);
      cout<<res.val<<newl;
    }
  }
}
void RMQandRAQ(){
  using namespace std;
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  constexpr char newl = '\n';
  
  int n,q;
  cin>>n>>q;
  vector<int> a(n);
  auto f = [](int a,int b){return a<b?a:b;};
  auto g = [](int a,int b){return a+b;};
  auto h = [](int a,int b){return a+b;};
  auto seg = make_lseg<int,int>(a,1e8,0,f,g,h);
  while(q--){
    int com;cin>>com;
    if(com==0){
      int s,t,x;cin>>s>>t>>x;
      seg.update(s,t+1,x);
    }
    if(com==1){
      int s,t;cin>>s>>t;
      int res = seg.fold(s,t+1);
      cout<<res<<newl;
    }
  }
}
void RSQandRUQ(){
  using namespace std;
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  constexpr char newl = '\n';
  using i64 = int64_t;
  struct ushi{
    using i64 = int64_t;
    i64 val;int sz;
    ushi():val(),sz(1){}
    ushi(i64 v):val(v),sz(1){}
    ushi(i64 v,int s):val(v),sz(s){}
  };

  i64 n,q;
  cin>>n>>q;
  vector<ushi> a(n);
  auto f = [](ushi a,ushi b){return ushi(a.val+b.val,a.sz+b.sz);};
  auto g = [](ushi a,i64 b){return ushi(b*a.sz,a.sz);};
  auto h = [](i64 a,i64 b){return b;};
  auto seg = make_lseg<ushi,i64>(a,{0,1},-100000,f,g,h);
  while(q--){
    int com;cin>>com;
    if(com==0){
      int s,t,x;cin>>s>>t>>x;
      seg.update(s,t+1,x);
    }
    if(com==1){
      int s,t;cin>>s>>t;
      ushi res = seg.fold(s,t+1);
      cout<<res.val<<newl;
    }
    //seg.dump();
  }
}

Measured memory_bytes: 51504