n,q=map(int,input().split()) a=list(map(int,input().split())) B=317 st1=[0]*B*B st2=[0]*B st3=[0]*B e=[(-a[i],0,i,i) for i in range(n)] for i in range(q): t,l,r,x=map(int,input().split()) e+=[(-x,i+1,l-1,r-1)] e.sort() ans=[0]*q for x,f,l,r in e: x=-x if f==0: y=l//B st1[l]+=x st2[y]+=x st3[y]+=1 else: a=0 yl=l//B yr=r//B if yl==yr: for i in range(l,r+1): a+=max(st1[i]-x,0) else: for i in range(l,yl*B+B): a+=max(st1[i]-x,0) for i in range(yr*B,r+1): a+=max(st1[i]-x,0) for i in range(yl+1,yr): a+=st2[i]-x*st3[i] ans[f-1]=a print(*ans,sep="\n")