#include using namespace std; template struct LazySegmentTree{ int n; vector dat; vector dat2; vector lazy; LazySegmentTree() {}; LazySegmentTree(int N) { n = 1; while(n < N) { n *= 2; } dat.resize(n*2-1,0); dat2.resize(n*2-1,0); lazy.resize(n*2-1,0); } void eval(int k,int l,int r) { if(lazy[k] == 0) return; if(k < n-1) { lazy[k*2+1] += lazy[k]; lazy[k*2+2] += lazy[k]; } dat[k] += lazy[k]; dat2[k] = dat[k]*dat[k]; lazy[k] = 0; } void update(int a, int b, T x, int k, int l, int r) { eval(k,l,r); if(a <= l && r <= b) { lazy[k] += x; eval(k,l,r); } else if(a < r && l < b) { update(a, b, x, k*2+1, l, (l+r)/2); update(a, b, x, k*2+2, (l+r)/2, r); dat2[k] = dat2[k*2+1]+dat2[k*2+2]; } } void update(int a, int b, T x) {//[a,b) update(a, b, x, 0, 0, n); } T query_sub(int a, int b, int k, int l, int r) { eval(k,l,r); if (r <= a || b <= l) { return 0; } else if (a <= l && r <= b) { return dat2[k]; } else { T vl = query_sub(a, b, k*2+1, l, (l+r)/2); T vr = query_sub(a, b, k*2+2, (l+r)/2, r); return vl+vr; } } T query(int a, int b) {//[a,b) return query_sub(a, b, 0, 0, n); } }; int main() { int N; cin >> N; vector A(N); LazySegmentTree tree(N); for(int i = 0; i < N; i++) { cin >> A[i]; tree.update(i,i+1,A[i]); } int Q; cin >> Q; while (Q--) { int f; cin >> f; if(f == 1) { int l,r,x; cin >> l >> r >> x; l--; tree.update(l,r,x); } else { int l,r; cin >> l >> r; l--; cout << tree.query(l,r) << endl; } } }