#include<iostream> #include<algorithm> using namespace std; #define lson o << 1, l, M #define rson o << 1 | 1, M+1, r #define lo o << 1 #define ro o << 1 | 1 const int N = 2e5 + 10; long long v[N << 2], lazy[N << 2]; inline void pushup(int o) { v[o] = v[o << 1] + v[o << 1 | 1]; } inline long long cal(long long a0, long long n) { return a0 * n + (n - 1) * n / 2; } inline void pushdown(int o, int ln, int rn) { if(lazy[o]) { lazy[lo] = lazy[o]; lazy[ro] = lazy[o] + ln; v[lo] = cal(lazy[o], ln); v[ro] = cal(lazy[ro], rn); lazy[o] = 0; } } void Build(int o, int l, int r) { if(l == r) { scanf("%lld", &v[o]); return ; } int M = (l + r) / 2; Build(lson); Build(rson); pushup(o); } void update(int L, int R, long long k, int o, int l, int r) { if(L <= l) { if(R >= r) { long long C = k + (l - L); v[o] = cal(C, r - l + 1); lazy[o] = C; return ; } } int M = (l + r) / 2; pushdown(o, M - l + 1, r - M); if(L <= M) update(L, R, k, lson); if(R > M) update(L, R, k, rson); pushup(o); } long long query(int L, int R, int o, int l, int r) { if(L <= l) { if(R >= r) return v[o]; } int M = (l + r) / 2; pushdown(o, M - l + 1, r - M); long long Sum = 0; if(L <= M) Sum += query(L, R, lson); if(R > M) Sum += query(L, R, rson); return Sum; } int main() { int n, m; scanf("%d%d", &n, &m); Build(1, 1, n); int op, l, r; long long k; while(m--) { scanf("%d%d%d", &op, &l, &r); if(op == 1) { scanf("%lld", &k); update(l, r, k, 1, 1, n); } else printf("%lld\n", query(l, r, 1, 1, n)); } return 0; }