import java.util.*; import java.io.*; public class Main { public static void main (String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] first = br.readLine().split(" ", 2); int n = Integer.parseInt(first[0]); int q = Integer.parseInt(first[1]); BinaryIndexedTree bit = new BinaryIndexedTree(n + 1); BinaryIndexedTree counts = new BinaryIndexedTree(n + 1); ArrayList list = new ArrayList<>(); String[] second = br.readLine().split(" ", n); for (int i = 1; i <= n; i++) { list.add(new Order(i, Integer.parseInt(second[i - 1]))); } for (int i = 0; i < q; i++) { String[] line = br.readLine().split(" ", 4); list.add(new Order(i, Integer.parseInt(line[1]), Integer.parseInt(line[2]), Integer.parseInt(line[3]))); } Collections.sort(list); long[] ans = new long[q]; for (Order x : list) { if (x.isValue()) { bit.add(x.idx, x.value); counts.add(x.idx, 1); } else { long tmp = bit.getSum(x.left, x.right) - counts.getSum(x.left, x.right) * x.value; ans[x.idx] = tmp; } } StringBuilder sb = new StringBuilder(); for (long x : ans) { sb.append(x).append("\n"); } System.out.print(sb); } static class Order implements Comparable { int idx; int left; int right; int value; public Order(int idx, int left, int right, int value) { this.idx = idx; this.left = left; this.right = right; this.value = value; } public Order(int idx, int value) { this(idx, 0, 0, value); } public boolean isValue() { return right == 0; } public int compareTo(Order another) { if (value == another.value) { return right - another.right; } else { return another.value - value; } } public String toString() { return idx + ":" + left + ":" + right + ":" + value; } } } class BinaryIndexedTree { int size; long[] tree; public BinaryIndexedTree(int size) { this.size = size; tree = new long[size]; } public void add(int idx, long value) { int mask = 1; while (idx < size) { if ((idx & mask) != 0) { tree[idx] += value; idx += mask; } mask <<= 1; } } public long getSum(int from, int to) { return getSum(to) - getSum(from - 1); } public long getSum(int x) { int mask = 1; long ans = 0; while (x > 0) { if ((x & mask) != 0) { ans += tree[x]; x -= mask; } mask <<= 1; } return ans; } }