n,q=map(int,input().split()) a=list(map(int,input().split())) B=317 st1=[0]*B*B st2=[[] for i in range(B)] st3=[[] for i in range(B)] for i in range(n): st1[i]=a[i] for i in range(B): st2[i]=sorted(st1[i*B:i*B+B]) st3[i]=st2[i].copy()+[0] for i in range(B): for j in range(B): st3[i][j]+=st3[i][j-1] from bisect import bisect_left for _ in range(q): t,*que,=map(int,input().split()) if t==1: l,r,x=que l-=1 r-=1 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): p=bisect_left(st2[i],x) a+=st3[i][B-1]-st3[i][p-1]-x*(B-p) print(a)