n,q = map(int,input().split()) a = list(map(int,input().split())) qs = [] for i in range(q): l,r,x = map(int,input().split()) qs.append((l-1,x,i,-1)) qs.append((r,x,i,1)) qs.sort(key = lambda x:x[0]) def compress(arr): *s, = set(arr) return {num: i for i,num in enumerate(sorted(s))} ca = compress(a) sa = sorted(a) seg_len = 1<<19 # > 5*(10**5) seg = [0]*(2*seg_len) seg2 = [0]*(2*seg_len) def update(pos,x,seg): pos += seg_len seg[pos] += x while True: pos >>= 1 if not pos: break seg[pos] = seg[pos<<1] + seg[pos<<1|1] def get_query(l,r,seg): l += seg_len; r += seg_len res = 0 while l < r: if l & 1: res += seg[l] l += 1 if r & 1: r -= 1 res += seg[r] l >>= 1; r >>= 1 return res now = 0 ans =[0]*q from bisect import bisect_left, bisect_right for l,x,i,ki in qs: while now < l: update(ca[a[now]], 1, seg) update(ca[a[now]], a[now], seg2) now += 1 xx = bisect_right(sa,x) s = get_query(0, xx, seg2) t = get_query(0, xx, seg) ans[i] +=ki*(s+(l-t)*x) print(*ans, sep = "\n")