#define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #include using namespace std; #include using namespace atcoder; #define REP(i,n) for(int i = 0; i < (int)n; i++) #define RREP(i,n) for(int i = (int)n-1; i >= 0; i--) #define LREP(i,n) for(LL i = 0; i < (LL)n; i++) #define Vi vector #define Vl vector #define P pair #define LP pair #define T3 tuple #define T4 tuple #define INF 1000000007 #define SIZE 300010 #define MOD 998244353 typedef long long LL; struct S { LL val = 0, d = 0, sum = 0; }; S op(S a, S b) { return S{ a.val + b.val,a.d + b.d,a.sum + b.sum }; } S e() { return S{ 0,0,0 }; } S mapping(LL f, S x) { S res = e(); res.val = x.val + 2 * f * x.sum + f * f * x.d; res.d = x.d; res.sum = f * x.d + x.sum; return res; } LL composition(LL f, LL g) { return f + g; } LL id() { return 0; } LL N; LL A[SIZE], sum[SIZE]; int main() { cin >> N; REP(i, N) cin >> A[i]; lazy_segtree seg(N); REP(i, N) { seg.set(i, S{ A[i] * A[i],1,A[i] }); } int Q; cin >> Q; REP(q, Q) { LL t, l, r, x; cin >> t >> l >> r; if (t == 1) { cin >> x; seg.apply(l - 1, r, x); } else { cout << seg.prod(l - 1, r).val << endl; } } }