#define PROBLEM "https://judge.yosupo.jp/problem/range_affine_range_sum"
#include"../../template/template.hpp"//usingnamespaceNyaan;#include"../../modint/montgomery-modint.hpp"usingmint=LazyMontgomeryModInt<998244353>;usingvm=vector<mint>;#include"../../math/affine-transformation.hpp"
#include"../../misc/fastio.hpp"//#include"../../lct/link-cut-tree-lazy.hpp"//usingT=pair<mint,mint>;usingE=Affine<mint>;Tf(Ta,Tb){returnT(a.first+b.first,a.second+b.second);}Tg(Ta,Eb){returnT(a.first*b.a+a.second*b.b,a.second);}Eh(Ea,Eb){returna*b;};Tts(Ta){returna;}usingnamespaceNyaan;voidNyaan::solve(){intN,Q;rd(N,Q);usingLCT=LazyLinkCutTree<T,E,f,g,h,ts>;LCTlct;vector<LCT::Ptr>vs(N);rep(i,N){inta;rd(a);vs[i]=lct.my_new(T(a,1));}for(inti=1;i<N;i++)lct.link(vs[i-1],vs[i]);while(Q--){intcmd;rd(cmd);if(cmd==0){intl,r,b,c;rd(l,r,b,c);lct.apply(vs[l],vs[r-1],E(b,c));}else{intl,r;rd(l,r);Tfold=lct.fold(vs[l],vs[r-1]);wtn(fold.first.get());}}}
#line 1 "verify/verify-yosupo-ds/yosupo-range-add-range-sum-linkcuttree.test.cpp"
#define PROBLEM "https://judge.yosupo.jp/problem/range_affine_range_sum"
#line 2 "template/template.hpp"
usingnamespacestd;// intrinstic#include<immintrin.h>#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cfenv>
#include<cfloat>
#include<chrono>
#include<cinttypes>
#include<climits>
#include<cmath>
#include<complex>
#include<cstdarg>
#include<cstddef>
#include<cstdint>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<deque>
#include<fstream>
#include<functional>
#include<initializer_list>
#include<iomanip>
#include<ios>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<stack>
#include<streambuf>
#include<string>
#include<tuple>
#include<type_traits>
#include<typeinfo>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>// utility#line 3 "template/util.hpp"
namespaceNyaan{usingll=longlong;usingi64=longlong;usingu64=unsignedlonglong;usingi128=__int128_t;usingu128=__uint128_t;template<typenameT>usingV=vector<T>;template<typenameT>usingVV=vector<vector<T>>;usingvi=vector<int>;usingvl=vector<longlong>;usingvd=V<double>;usingvs=V<string>;usingvvi=vector<vector<int>>;usingvvl=vector<vector<longlong>>;template<typenameT>usingminpq=priority_queue<T,vector<T>,greater<T>>;template<typenameT,typenameU>structP:pair<T,U>{template<typename...Args>P(Args...args):pair<T,U>(args...){}usingpair<T,U>::first;usingpair<T,U>::second;P&operator+=(constP&r){first+=r.first;second+=r.second;return*this;}P&operator-=(constP&r){first-=r.first;second-=r.second;return*this;}P&operator*=(constP&r){first*=r.first;second*=r.second;return*this;}template<typenameS>P&operator*=(constS&r){first*=r,second*=r;return*this;}Poperator+(constP&r)const{returnP(*this)+=r;}Poperator-(constP&r)const{returnP(*this)-=r;}Poperator*(constP&r)const{returnP(*this)*=r;}template<typenameS>Poperator*(constS&r)const{returnP(*this)*=r;}Poperator-()const{returnP{-first,-second};}};usingpl=P<ll,ll>;usingpi=P<int,int>;usingvp=V<pl>;constexprintinf=1001001001;constexprlonglonginfLL=4004004004004004004LL;template<typenameT>intsz(constT&t){returnt.size();}template<typenameT,typenameU>inlineboolamin(T&x,Uy){return(y<x)?(x=y,true):false;}template<typenameT,typenameU>inlineboolamax(T&x,Uy){return(x<y)?(x=y,true):false;}template<typenameT>inlineTMax(constvector<T>&v){return*max_element(begin(v),end(v));}template<typenameT>inlineTMin(constvector<T>&v){return*min_element(begin(v),end(v));}template<typenameT>inlinelonglongSum(constvector<T>&v){returnaccumulate(begin(v),end(v),0LL);}template<typenameT>intlb(constvector<T>&v,constT&a){returnlower_bound(begin(v),end(v),a)-begin(v);}template<typenameT>intub(constvector<T>&v,constT&a){returnupper_bound(begin(v),end(v),a)-begin(v);}constexprlonglongTEN(intn){longlongret=1,x=10;for(;n;x*=x,n>>=1)ret*=(n&1?x:1);returnret;}template<typenameT,typenameU>pair<T,U>mkp(constT&t,constU&u){returnmake_pair(t,u);}template<typenameT>vector<T>mkrui(constvector<T>&v,boolrev=false){vector<T>ret(v.size()+1);if(rev){for(inti=int(v.size())-1;i>=0;i--)ret[i]=v[i]+ret[i+1];}else{for(inti=0;i<int(v.size());i++)ret[i+1]=ret[i]+v[i];}returnret;};template<typenameT>vector<T>mkuni(constvector<T>&v){vector<T>ret(v);sort(ret.begin(),ret.end());ret.erase(unique(ret.begin(),ret.end()),ret.end());returnret;}template<typenameF>vector<int>mkord(intN,Ff){vector<int>ord(N);iota(begin(ord),end(ord),0);sort(begin(ord),end(ord),f);returnord;}template<typenameT>vector<int>mkinv(vector<T>&v){intmax_val=*max_element(begin(v),end(v));vector<int>inv(max_val+1,-1);for(inti=0;i<(int)v.size();i++)inv[v[i]]=i;returninv;}vector<int>mkiota(intn){vector<int>ret(n);iota(begin(ret),end(ret),0);returnret;}template<typenameT>Tmkrev(constT&v){Tw{v};reverse(begin(w),end(w));returnw;}template<typenameT>boolnxp(T&v){returnnext_permutation(begin(v),end(v));}// 返り値の型は入力の T に依存// i 要素目 : [0, a[i])template<typenameT>vector<vector<T>>product(constvector<T>&a){vector<vector<T>>ret;vector<T>v;autodfs=[&](autorc,inti)->void{if(i==(int)a.size()){ret.push_back(v);return;}for(intj=0;j<a[i];j++)v.push_back(j),rc(rc,i+1),v.pop_back();};dfs(dfs,0);returnret;}// F : void(T&), mod を取る操作// T : 整数型のときはオーバーフローに注意するtemplate<typenameT,typenameF>TPower(Ta,longlongn,constT&I,F&&f){static_assert(std::is_invocable_r_v<void,F&,T&>,"Power callback must be callable as void(T&)");Tres=I;for(;n;std::invoke(f,a=a*a),n>>=1){if(n&1)std::invoke(f,res=res*a);}returnres;}// T : 整数型のときはオーバーフローに注意するtemplate<typenameT>TPower(Ta,longlongn,constT&I=T{1}){autono_op=[](T&)->void{};returnPower(a,n,I,no_op);}template<typenameT>TRev(constT&v){Tres=v;reverse(begin(res),end(res));returnres;}template<typenameT>vector<T>Transpose(constvector<T>&v){usingU=typenameT::value_type;if(v.empty())return{};intH=v.size(),W=v[0].size();vectorres(W,T(H,U{}));for(inti=0;i<H;i++){for(intj=0;j<W;j++){res[j][i]=v[i][j];}}returnres;}template<typenameT>vector<T>Rotate(constvector<T>&v,intclockwise=true){usingU=typenameT::value_type;intH=v.size(),W=v[0].size();vectorres(W,T(H,U{}));for(inti=0;i<H;i++){for(intj=0;j<W;j++){if(clockwise){res[W-1-j][i]=v[i][j];}else{res[j][H-1-i]=v[i][j];}}}returnres;}}// namespace Nyaan#line 58 "template/template.hpp"
// bit operation#line 1 "template/bitop.hpp"
namespaceNyaan{__attribute__((target("popcnt")))inlineintpopcnt(constu64&a){return__builtin_popcountll(a);}inlineintlsb(constu64&a){returna?__builtin_ctzll(a):64;}inlineintctz(constu64&a){returna?__builtin_ctzll(a):64;}inlineintmsb(constu64&a){returna?63-__builtin_clzll(a):-1;}template<typenameT>inlineintgbit(constT&a,inti){return(a>>i)&1;}template<typenameT>inlinevoidsbit(T&a,inti,boolb){if(gbit(a,i)!=b)a^=T(1)<<i;}constexprlonglongPW(intn){return1LL<<n;}constexprlonglongMSK(intn){return(1LL<<n)-1;}}// namespace Nyaan#line 61 "template/template.hpp"
// inout#line 1 "template/inout.hpp"
namespaceNyaan{template<typenameT,typenameU>ostream&operator<<(ostream&os,constpair<T,U>&p){os<<p.first<<" "<<p.second;returnos;}template<typenameT,typenameU>istream&operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;returnis;}template<typenameT>ostream&operator<<(ostream&os,constvector<T>&v){ints=(int)v.size();for(inti=0;i<s;i++)os<<(i?" ":"")<<v[i];returnos;}template<typenameT>istream&operator>>(istream&is,vector<T>&v){for(auto&x:v)is>>x;returnis;}istream&operator>>(istream&is,__int128_t&x){stringS;is>>S;x=0;intflag=0;for(auto&c:S){if(c=='-'){flag=true;continue;}x*=10;x+=c-'0';}if(flag)x=-x;returnis;}istream&operator>>(istream&is,__uint128_t&x){stringS;is>>S;x=0;for(auto&c:S){x*=10;x+=c-'0';}returnis;}ostream&operator<<(ostream&os,__int128_tx){if(x==0)returnos<<0;if(x<0)os<<'-',x=-x;stringS;while(x)S.push_back('0'+x%10),x/=10;reverse(begin(S),end(S));returnos<<S;}ostream&operator<<(ostream&os,__uint128_tx){if(x==0)returnos<<0;stringS;while(x)S.push_back('0'+x%10),x/=10;reverse(begin(S),end(S));returnos<<S;}voidin(){}template<typenameT,class...U>voidin(T&t,U&...u){cin>>t;in(u...);}voidout(){cout<<"\n";}template<typenameT,class...U,charsep=' '>voidout(constT&t,constU&...u){cout<<t;if(sizeof...(u))cout<<sep;out(u...);}structIoSetupNya{IoSetupNya(){cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);cerr<<fixed<<setprecision(7);}}iosetupnya;}// namespace Nyaan#line 64 "template/template.hpp"
// debug#line 1 "template/debug.hpp"
namespaceDebugImpl{template<typenameU,typename=void>structis_specialize:false_type{};template<typenameU>structis_specialize<U,typenameconditional<false,typenameU::iterator,void>::type>:true_type{};template<typenameU>structis_specialize<U,typenameconditional<false,decltype(U::first),void>::type>:true_type{};template<typenameU>structis_specialize<U,enable_if_t<is_integral<U>::value,void>>:true_type{};voiddump(constchar&t){cerr<<t;}voiddump(conststring&t){cerr<<t;}voiddump(constbool&t){cerr<<(t?"true":"false");}voiddump(__int128_tt){if(t==0)cerr<<0;if(t<0)cerr<<'-',t=-t;stringS;while(t)S.push_back('0'+t%10),t/=10;reverse(begin(S),end(S));cerr<<S;}voiddump(__uint128_tt){if(t==0)cerr<<0;stringS;while(t)S.push_back('0'+t%10),t/=10;reverse(begin(S),end(S));cerr<<S;}template<typenameU,enable_if_t<!is_specialize<U>::value,nullptr_t>=nullptr>voiddump(constU&t){cerr<<t;}template<typenameT>voiddump(constT&t,enable_if_t<is_integral<T>::value>*=nullptr){stringres;if(t==Nyaan::inf)res="inf";ifconstexpr(is_signed<T>::value){if(t==-Nyaan::inf)res="-inf";}ifconstexpr(sizeof(T)==8){if(t==Nyaan::infLL)res="inf";ifconstexpr(is_signed<T>::value){if(t==-Nyaan::infLL)res="-inf";}}if(res.empty())res=to_string(t);cerr<<res;}template<typenameT,typenameU>voiddump(constpair<T,U>&);template<typenameT>voiddump(constpair<T*,int>&);template<typenameT>voiddump(constT&t,enable_if_t<!is_void<typenameT::iterator>::value>*=nullptr){cerr<<"[ ";for(autoit=t.begin();it!=t.end();){dump(*it);cerr<<(++it==t.end()?"":", ");}cerr<<" ]";}template<typenameT,typenameU>voiddump(constpair<T,U>&t){cerr<<"( ";dump(t.first);cerr<<", ";dump(t.second);cerr<<" )";}template<typenameT>voiddump(constpair<T*,int>&t){cerr<<"[ ";for(inti=0;i<t.second;i++){dump(t.first[i]);cerr<<(i==t.second-1?"":", ");}cerr<<" ]";}voidtrace(){cerr<<endl;}template<typenameHead,typename...Tail>voidtrace(Head&&head,Tail&&...tail){cerr<<" ";dump(head);if(sizeof...(tail)!=0)cerr<<",";trace(std::forward<Tail>(tail)...);}}// namespace DebugImpl#ifdef NyaanDebug
#define trc(...) \
do { \
cerr << "## " << #__VA_ARGS__ << " = "; \
DebugImpl::trace(__VA_ARGS__); \
} while (0)
#else
#define trc(...) (void(0))
#endif
#ifdef NyaanLocal
#define trc2(...) \
do { \
cerr << "## " << #__VA_ARGS__ << " = "; \
DebugImpl::trace(__VA_ARGS__); \
} while (0)
#else
#define trc2(...) (void(0))
#endif
#line 67 "template/template.hpp"
// macro#line 1 "template/macro.hpp"
#define each(x, v) for (auto&& x : v)
#define each2(x, y, v) for (auto&& [x, y] : v)
#define all(v) (v).begin(), (v).end()
#define rep(i, N) for (long long i = 0; i < (long long)(N); i++)
#define repr(i, N) for (long long i = (long long)(N)-1; i >= 0; i--)
#define rep1(i, N) for (long long i = 1; i <= (long long)(N); i++)
#define repr1(i, N) for (long long i = (N); (long long)(i) > 0; i--)
#define reg(i, a, b) for (long long i = (a); i < (b); i++)
#define regr(i, a, b) for (long long i = (b)-1; i >= (a); i--)
#define fi first
#define se second
#define ini(...) \
int __VA_ARGS__; \
in(__VA_ARGS__)
#define inl(...) \
long long __VA_ARGS__; \
in(__VA_ARGS__)
#define ins(...) \
string __VA_ARGS__; \
in(__VA_ARGS__)
#define in2(s, t) \
for (int i = 0; i < (int)s.size(); i++) { \
in(s[i], t[i]); \
}
#define in3(s, t, u) \
for (int i = 0; i < (int)s.size(); i++) { \
in(s[i], t[i], u[i]); \
}
#define in4(s, t, u, v) \
for (int i = 0; i < (int)s.size(); i++) { \
in(s[i], t[i], u[i], v[i]); \
}
#define die(...) \
do { \
Nyaan::out(__VA_ARGS__); \
return; \
} while (0)
#line 70 "template/template.hpp"
namespaceNyaan{voidsolve();}intmain(){Nyaan::solve();}#line 4 "verify/verify-yosupo-ds/yosupo-range-add-range-sum-linkcuttree.test.cpp"
//usingnamespaceNyaan;#line 2 "modint/montgomery-modint.hpp"
#line 5 "modint/montgomery-modint.hpp"
template<uint32_tmod>structLazyMontgomeryModInt{usingmint=LazyMontgomeryModInt;usingi32=int32_t;usingu32=uint32_t;usingu64=uint64_t;staticconstexpru32get_r(){u32ret=mod;for(i32i=0;i<4;++i)ret*=2-mod*ret;returnret;}staticconstexpru32r=get_r();staticconstexpru32n2=-u64(mod)%mod;static_assert(mod<(1<<30),"invalid, mod >= 2 ^ 30");static_assert((mod&1)==1,"invalid, mod % 2 == 0");static_assert(r*mod==1,"this code has bugs.");u32a;constexprLazyMontgomeryModInt():a(0){}constexprLazyMontgomeryModInt(constint64_t&b):a(reduce(u64(b%mod+mod)*n2)){};staticconstexpru32reduce(constu64&b){return(b+u64(u32(b)*u32(-r))*mod)>>32;}constexprmint&operator+=(constmint&b){if(i32(a+=b.a-2*mod)<0)a+=2*mod;return*this;}constexprmint&operator-=(constmint&b){if(i32(a-=b.a)<0)a+=2*mod;return*this;}constexprmint&operator*=(constmint&b){a=reduce(u64(a)*b.a);return*this;}constexprmint&operator/=(constmint&b){*this*=b.inverse();return*this;}constexprmintoperator+(constmint&b)const{returnmint(*this)+=b;}constexprmintoperator-(constmint&b)const{returnmint(*this)-=b;}constexprmintoperator*(constmint&b)const{returnmint(*this)*=b;}constexprmintoperator/(constmint&b)const{returnmint(*this)/=b;}constexprbooloperator==(constmint&b)const{return(a>=mod?a-mod:a)==(b.a>=mod?b.a-mod:b.a);}constexprbooloperator!=(constmint&b)const{return(a>=mod?a-mod:a)!=(b.a>=mod?b.a-mod:b.a);}constexprmintoperator-()const{returnmint()-mint(*this);}constexprmintoperator+()const{returnmint(*this);}constexprmintpow(u64n)const{mintret(1),mul(*this);while(n>0){if(n&1)ret*=mul;mul*=mul;n>>=1;}returnret;}constexprmintinverse()const{intx=get(),y=mod,u=1,v=0,t=0,tmp=0;while(y>0){t=x/y;x-=t*y,u-=t*v;tmp=x,x=y,y=tmp;tmp=u,u=v,v=tmp;}returnmint{u};}friendstd::ostream&operator<<(std::ostream&os,constmint&b){returnos<<b.get();}friendstd::istream&operator>>(std::istream&is,mint&b){int64_tt;is>>t;b=LazyMontgomeryModInt<mod>(t);return(is);}constexpru32get()const{u32ret=reduce(a);returnret>=mod?ret-mod:ret;}staticconstexpru32get_mod(){returnmod;}};#line 8 "verify/verify-yosupo-ds/yosupo-range-add-range-sum-linkcuttree.test.cpp"
usingmint=LazyMontgomeryModInt<998244353>;usingvm=vector<mint>;#line 2 "math/affine-transformation.hpp"
template<typenamemint>structAffine{minta,b;constexprAffine():a(1),b(0){}constexprAffine(mint_a,mint_b):a(_a),b(_b){}// R(L(x))friendAffineoperator*(constAffine&l,constAffine&r){returnAffine(l.a*r.a,l.b*r.a+r.b);}mintoperator()(mintx)const{returna*x+b;}Affineoperator()(constAffine&r)const{returnr*(*this);}booloperator==(constAffine&r)const{returna==r.a&&b==r.b;}booloperator!=(constAffine&r)const{returna!=r.a||b!=r.b;}friendostream&operator<<(ostream&os,constAffine&r){os<<"( "<<r.a<<", "<<r.b<<" )";returnos;}};/**
* @brief アフィン変換
*/#line 2 "misc/fastio.hpp"
#line 9 "misc/fastio.hpp"
usingnamespacestd;#line 2 "internal/internal-type-traits.hpp"
#line 4 "internal/internal-type-traits.hpp"
usingnamespacestd;namespacenyaan_internal{template<typenameT>usingis_broadly_integral=typenameconditional_t<is_integral_v<T>||is_same_v<T,__int128_t>||is_same_v<T,__uint128_t>,true_type,false_type>::type;template<typenameT>usingis_broadly_signed=typenameconditional_t<is_signed_v<T>||is_same_v<T,__int128_t>,true_type,false_type>::type;template<typenameT>usingis_broadly_unsigned=typenameconditional_t<is_unsigned_v<T>||is_same_v<T,__uint128_t>,true_type,false_type>::type;#define ENABLE_VALUE(x) \
template <typename T> \
constexpr bool x##_v = x<T>::value;
ENABLE_VALUE(is_broadly_integral);ENABLE_VALUE(is_broadly_signed);ENABLE_VALUE(is_broadly_unsigned);#undef ENABLE_VALUE
#define ENABLE_HAS_TYPE(var) \
template <class, class = void> \
struct has_##var : false_type {}; \
template <class T> \
struct has_##var<T, void_t<typename T::var>> : true_type {}; \
template <class T> \
constexpr auto has_##var##_v = has_##var<T>::value;
#define ENABLE_HAS_VAR(var) \
template <class, class = void> \
struct has_##var : false_type {}; \
template <class T> \
struct has_##var<T, void_t<decltype(T::var)>> : true_type {}; \
template <class T> \
constexpr auto has_##var##_v = has_##var<T>::value;
}// namespace nyaan_internal#line 13 "misc/fastio.hpp"
namespacefastio{staticconstexprintSZ=1<<17;staticconstexprintoffset=64;charinbuf[SZ],outbuf[SZ];intin_left=0,in_right=0,out_right=0;structPre{charnum[40000];constexprPre():num(){for(inti=0;i<10000;i++){intn=i;for(intj=3;j>=0;j--){num[i*4+j]=n%10+'0';n/=10;}}}}constexprpre;voidload(){intlen=in_right-in_left;memmove(inbuf,inbuf+in_left,len);in_right=len+fread(inbuf+len,1,SZ-len,stdin);in_left=0;}voidflush(){fwrite(outbuf,1,out_right,stdout);out_right=0;}voidskip_space(){if(in_left+offset>in_right)load();while(inbuf[in_left]<=' ')in_left++;}voidsingle_read(char&c){if(in_left+offset>in_right)load();skip_space();c=inbuf[in_left++];}voidsingle_read(string&S){skip_space();while(true){if(in_left==in_right)load();inti=in_left;for(;i!=in_right;i++){if(inbuf[i]<=' ')break;}copy(inbuf+in_left,inbuf+i,back_inserter(S));in_left=i;if(i!=in_right)break;}}template<typenameT,enable_if_t<nyaan_internal::is_broadly_integral_v<T>>*=nullptr>voidsingle_read(T&x){if(in_left+offset>in_right)load();skip_space();charc=inbuf[in_left++];[[maybe_unused]]boolminus=false;ifconstexpr(nyaan_internal::is_broadly_signed_v<T>){if(c=='-')minus=true,c=inbuf[in_left++];}x=0;while(c>='0'){x=x*10+(c&15);c=inbuf[in_left++];}ifconstexpr(nyaan_internal::is_broadly_signed_v<T>){if(minus)x=-x;}}voidrd(){}template<typenameHead,typename...Tail>voidrd(Head&head,Tail&...tail){single_read(head);rd(tail...);}voidsingle_write(constchar&c){if(out_right>SZ-offset)flush();outbuf[out_right++]=c;}voidsingle_write(constbool&b){if(out_right>SZ-offset)flush();outbuf[out_right++]=b?'1':'0';}voidsingle_write(conststring&S){flush(),fwrite(S.data(),1,S.size(),stdout);}voidsingle_write(constchar*p){flush(),fwrite(p,1,strlen(p),stdout);}template<typenameT,enable_if_t<nyaan_internal::is_broadly_integral_v<T>>*=nullptr>voidsingle_write(constT&_x){if(out_right>SZ-offset)flush();if(_x==0){outbuf[out_right++]='0';return;}Tx=_x;ifconstexpr(nyaan_internal::is_broadly_signed_v<T>){if(x<0)outbuf[out_right++]='-',x=-x;}constexprintbuffer_size=sizeof(T)*10/4;charbuf[buffer_size];inti=buffer_size;while(x>=10000){i-=4;memcpy(buf+i,pre.num+(x%10000)*4,4);x/=10000;}if(x<100){if(x<10){outbuf[out_right]='0'+x;++out_right;}else{uint32_tq=(uint32_t(x)*205)>>11;uint32_tr=uint32_t(x)-q*10;outbuf[out_right]='0'+q;outbuf[out_right+1]='0'+r;out_right+=2;}}else{if(x<1000){memcpy(outbuf+out_right,pre.num+(x<<2)+1,3);out_right+=3;}else{memcpy(outbuf+out_right,pre.num+(x<<2),4);out_right+=4;}}memcpy(outbuf+out_right,buf+i,buffer_size-i);out_right+=buffer_size-i;}voidwt(){}template<typenameHead,typename...Tail>voidwt(constHead&head,constTail&...tail){single_write(head);wt(std::forward<constTail>(tail)...);}template<typename...Args>voidwtn(constArgs&...x){wt(std::forward<constArgs>(x)...);wt('\n');}structDummy{Dummy(){atexit(flush);}}dummy;}// namespace fastiousingfastio::rd;usingfastio::skip_space;usingfastio::wt;usingfastio::wtn;#line 12 "verify/verify-yosupo-ds/yosupo-range-add-range-sum-linkcuttree.test.cpp"
//#line 2 "lct/link-cut-tree-lazy.hpp"
#line 2 "lct/splay-lazy-reversible.hpp"
#line 2 "lct/lazy-reversible-bbst-base.hpp"
template<typenameTree,typenameNode,typenameT,typenameE,T(*f)(T,T),T(*g)(T,E),E(*h)(E,E),T(*ts)(T)>structLazyReversibleBBST:Tree{usingTree::merge;usingTree::split;usingtypenameTree::Ptr;LazyReversibleBBST()=default;voidtoggle(Ptrt){if(!t)return;swap(t->l,t->r);t->sum=ts(t->sum);t->rev^=true;}Tfold(Ptr&t,inta,intb){autox=split(t,a);autoy=split(x.second,b-a);autoret=sum(y.first);t=merge(x.first,merge(y.first,y.second));returnret;}voidreverse(Ptr&t,inta,intb){autox=split(t,a);autoy=split(x.second,b-a);toggle(y.first);t=merge(x.first,merge(y.first,y.second));}voidapply(Ptr&t,inta,intb,constE&e){autox=split(t,a);autoy=split(x.second,b-a);propagate(y.first,e);t=merge(x.first,merge(y.first,y.second));}protected:inlineTsum(constPtrt){returnt?t->sum:T();}Ptrupdate(Ptrt)override{if(!t)returnt;t->cnt=1;t->sum=t->key;if(t->l)t->cnt+=t->l->cnt,t->sum=f(t->l->sum,t->sum);if(t->r)t->cnt+=t->r->cnt,t->sum=f(t->sum,t->r->sum);returnt;}voidpush(Ptrt)override{if(!t)return;if(t->rev){if(t->l)toggle(t->l);if(t->r)toggle(t->r);t->rev=false;}if(t->lazy!=E()){if(t->l)propagate(t->l,t->lazy);if(t->r)propagate(t->r,t->lazy);t->lazy=E();}}voidpropagate(Ptrt,constE&x){t->lazy=h(t->lazy,x);t->key=g(t->key,x);t->sum=g(t->sum,x);}};/**
* @brief 遅延伝搬反転可能平衡二分木(基底クラス)
*/#line 2 "lct/splay-base.hpp"
template<typenameNode>structSplayTreeBase{usingPtr=Node*;template<typename...Args>Ptrmy_new(constArgs&...args){returnnewNode(args...);}voidmy_del(Ptrp){deletep;}boolis_root(Ptrt){return!(t->p)||(t->p->l!=t&&t->p->r!=t);}intsize(Ptrt)const{returncount(t);}virtualvoidsplay(Ptrt){if(!t)return;push(t);while(!is_root(t)){Ptrq=t->p;if(is_root(q)){push(q),push(t);rot(t);}else{Ptrr=q->p;push(r),push(q),push(t);if(pos(q)==pos(t))rot(q),rot(t);elserot(t),rot(t);}}}Ptrget_left(Ptrt){while(t->l)push(t),t=t->l;returnt;}Ptrget_right(Ptrt){while(t->r)push(t),t=t->r;returnt;}Ptrkth(Ptrt,intk){while(true){push(t);intlsz=count(t->l);if(k<lsz){t=t->l;}elseif(k==lsz){splay(t);returnt;}else{k-=lsz+1;t=t->r;}}}pair<Ptr,Ptr>split(Ptrt,intk){if(!t)return{nullptr,nullptr};if(k==0)return{nullptr,t};if(k==count(t))return{t,nullptr};Ptrr=kth(t,k);Ptrl=r->l;r->l=nullptr;if(l)l->p=nullptr;update(r);return{l,r};}Ptrmerge(Ptrl,Ptrr){if(!l&&!r)returnnullptr;if(!l)returnr;if(!r)returnl;l=kth(l,count(l)-1);l->r=r;r->p=l;update(l);returnl;}usingKey=decltype(Node::key);Ptrbuild(constvector<Key>&v){returnbuild(0,v.size(),v);}Ptrbuild(intl,intr,constvector<Key>&v){if(l==r)returnnullptr;if(l+1==r)returnmy_new(v[l]);returnmerge(build(l,(l+r)>>1,v),build((l+r)>>1,r,v));}template<typename...Args>voidinsert(Ptr&t,intk,constArgs&...args){splay(t);autox=split(t,k);t=merge(merge(x.first,my_new(args...)),x.second);}voiderase(Ptr&t,intk){splay(t);autox=split(t,k);autoy=split(x.second,1);my_del(y.first);t=merge(x.first,y.second);}virtualPtrupdate(Ptrt)=0;protected:inlineintcount(Ptrt)const{returnt?t->cnt:0;}virtualvoidpush(Ptrt)=0;Ptrbuild(constvector<Ptr>&v){returnbuild(0,v.size(),v);}Ptrbuild(intl,intr,constvector<Ptr>&v){if(l+1>=r)returnv[l];returnmerge(build(l,(l+r)>>1,v),build((l+r)>>1,r,v));}inlineintpos(Ptrt){if(t->p){if(t->p->l==t)return-1;if(t->p->r==t)return1;}return0;}virtualvoidrot(Ptrt){Ptrx=t->p,y=x->p;if(pos(t)==-1){if((x->l=t->r))t->r->p=x;t->r=x,x->p=t;}else{if((x->r=t->l))t->l->p=x;t->l=x,x->p=t;}update(x),update(t);if((t->p=y)){if(y->l==x)y->l=t;if(y->r==x)y->r=t;}}};/**
* @brief Splay Tree(base)
*/#line 5 "lct/splay-lazy-reversible.hpp"
template<typenameT,typenameE>structLazyReversibleSplayTreeNode{usingPtr=LazyReversibleSplayTreeNode*;Ptrl,r,p;Tkey,sum;Elazy;intcnt;boolrev;LazyReversibleSplayTreeNode(constT&t=T(),constE&e=E()):l(),r(),p(),key(t),sum(t),lazy(e),cnt(1),rev(false){}};template<typenameT,typenameE,T(*f)(T,T),T(*g)(T,E),E(*h)(E,E),T(*ts)(T)>structLazyReversibleSplayTree:LazyReversibleBBST<SplayTreeBase<LazyReversibleSplayTreeNode<T,E>>,LazyReversibleSplayTreeNode<T,E>,T,E,f,g,h,ts>{usingNode=LazyReversibleSplayTreeNode<T,E>;};/**
* @brief 遅延伝搬反転可能Splay Tree
*/#line 4 "lct/link-cut-tree-lazy.hpp"
//#line 2 "lct/link-cut-base.hpp"
template<typenameSplay>structLinkCutBase:Splay{usingNode=typenameSplay::Node;usingPtr=Node*;virtualPtrexpose(Ptrt){Ptrrp=nullptr;for(Ptrcur=t;cur;cur=cur->p){this->splay(cur);cur->r=rp;this->update(cur);rp=cur;}this->splay(t);returnrp;}virtualvoidlink(Ptru,Ptrv){evert(u);expose(v);u->p=v;}voidcut(Ptru,Ptrv){evert(u);expose(v);assert(u->p==v);v->l=u->p=nullptr;this->update(v);}voidevert(Ptrt){expose(t);this->toggle(t);this->push(t);}Ptrlca(Ptru,Ptrv){if(get_root(u)!=get_root(v))returnnullptr;expose(u);returnexpose(v);}Ptrget_kth(Ptrx,intk){expose(x);while(x){this->push(x);if(x->r&&x->r->sz>k){x=x->r;}else{if(x->r)k-=x->r->sz;if(k==0)returnx;k-=1;x=x->l;}}returnnullptr;}Ptrget_root(Ptrx){expose(x);while(x->l)this->push(x),x=x->l;returnx;}Ptrget_parent(Ptrx){expose(x);Ptrp=x->l;if(p==nullptr)returnnullptr;while(true){this->push(p);if(p->r==nullptr)returnp;p=p->r;}exit(1);}virtualvoidset_key(Ptrt,constdecltype(Node::key)&key){this->splay(t);t->key=key;this->update(t);}virtualdecltype(Node::key)get_key(Ptrt){returnt->key;}decltype(Node::key)fold(Ptru,Ptrv){evert(u);expose(v);returnv->sum;}};/**
* @brief Link/Cut Tree(base)
*/#line 7 "lct/link-cut-tree-lazy.hpp"
template<typenameT,typenameE,T(*f)(T,T),T(*g)(T,E),E(*h)(E,E),T(*ts)(T)>structLazyLinkCutTree:LinkCutBase<LazyReversibleSplayTree<T,E,f,g,h,ts>>{usingbase=LinkCutBase<LazyReversibleSplayTree<T,E,f,g,h,ts>>;usingPtr=typenamebase::Ptr;voidset_key(Ptrt,constT&key)override{this->evert(t);t->key=key;this->update(t);}Tget_key(Ptrt)override{this->evert(t);returnt->key;}voidapply(Ptru,Ptrv,constE&e){this->evert(u);this->expose(v);this->propagate(v,e);}};/**
* @brief 遅延伝搬Link/Cut Tree
*/#line 14 "verify/verify-yosupo-ds/yosupo-range-add-range-sum-linkcuttree.test.cpp"
//usingT=pair<mint,mint>;usingE=Affine<mint>;Tf(Ta,Tb){returnT(a.first+b.first,a.second+b.second);}Tg(Ta,Eb){returnT(a.first*b.a+a.second*b.b,a.second);}Eh(Ea,Eb){returna*b;};Tts(Ta){returna;}usingnamespaceNyaan;voidNyaan::solve(){intN,Q;rd(N,Q);usingLCT=LazyLinkCutTree<T,E,f,g,h,ts>;LCTlct;vector<LCT::Ptr>vs(N);rep(i,N){inta;rd(a);vs[i]=lct.my_new(T(a,1));}for(inti=1;i<N;i++)lct.link(vs[i-1],vs[i]);while(Q--){intcmd;rd(cmd);if(cmd==0){intl,r,b,c;rd(l,r,b,c);lct.apply(vs[l],vs[r-1],E(b,c));}else{intl,r;rd(l,r);Tfold=lct.fold(vs[l],vs[r-1]);wtn(fold.first.get());}}}