#include using namespace std; const int N = 1000010; typedef long long LL; int n, m; LL a[N]; LL c1[N], c2[N]; #define lowbit(x) (x & -x) void add(LL c[], LL x, LL v) { while (x < N) c[x] += v, x += lowbit(x); } LL sum(LL c[], LL x) { LL res = 0; while (x) res += c[x], x -= lowbit(x); return res; } LL query(LL x) { return sum(c1, x) * (x + 1) - sum(c2, x); } int main() { #ifndef ONLINE_JUDGE freopen("P3372.in", "r", stdin); #endif scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%lld", &a[i]); add(c1, i, a[i]), add(c1, i + 1, -a[i]); add(c2, i, a[i] * i), add(c2, i + 1, -(i + 1) * a[i]); } while (m--) { int x, y, k, op; scanf("%d", &op); if (op == 2) { scanf("%d%d", &x, &y); printf("%lld\n", query(y) - query(x - 1)); } else { scanf("%d%d%d", &x, &y, &k); add(c1, x, k), add(c1, y + 1, -k); add(c2, x, k * x), add(c2, y + 1, (y + 1) * -k); } } return 0; }