#include using namespace std; #include #include template struct lazysegtree{ using F=function; using G=function; const F calcfn,lazycalcfn; const G updatefn; int n; T defvalue; vectordat,lazy; vectorlazyflag; lazysegtree(int n_=0,T defvalue_=0, const F calcfn_=[](T a,T b){return a+b;}, const F lazycalcfn_=[](T a,T b){return a+b;}, const G updatefn_=[](T a,T b,int l,int r){return a+b*(r-l);} ):defvalue(defvalue_), calcfn(calcfn_),lazycalcfn(lazycalcfn_),updatefn(updatefn_) { n=1; while(n&v) { for(int i=0;i=0;i--)dat[i]=calcfn(dat[2*i+1],dat[2*i+2]); } void eval(int i,int l,int r) { if(lazyflag[i]) { dat[i]=updatefn(dat[i],lazy[i],l,r); if(r-l>1) { lazy[2*i+1]=lazyflag[2*i+1]?lazycalcfn(lazy[2*i+1],lazy[i]):lazy[i]; lazy[2*i+2]=lazyflag[2*i+2]?lazycalcfn(lazy[2*i+2],lazy[i]):lazy[i]; lazyflag[2*i+1]=lazyflag[2*i+2]=true; } lazyflag[i]=false; } } void update(int a,int b,T x,int k=0,int l=0,int r=-1)//[a,b) { if(r<0)r=n; eval(k,l,r); if(b<=l||r<=a)return; else if(a<=l&&r<=b) { lazy[k]=lazyflag[k]?lazycalcfn(lazy[k],x):x; lazyflag[k]=true; eval(k,l,r); } else { update(a,b,x,2*k+1,l,(l+r)/2); update(a,b,x,2*k+2,(l+r)/2,r); dat[k]=calcfn(dat[2*k+1],dat[2*k+2]); } } T query(int a,int b,int k=0,int l=0,int r=-1)//[a,b) { if(r<0)r=n; eval(k,l,r); if(b<=l||r<=a)return defvalue; else if(a<=l&&r<=b)return dat[k]; else return calcfn( query(a,b,2*k+1,l,(l+r)/2), query(a,b,2*k+2,(l+r)/2,r) ); } }; main() { int N; cin>>N; vectorA(N); for(int i=0;i>A[i]; lazysegtreeP(N,(long)9e18, [](long a,long b){return a>Q; for(;Q--;) { int k,l,r,c;cin>>k>>l>>r>>c; if(k==1) { P.update(l-1,r,c); } else { cout<