#include #include using namespace std; using namespace atcoder; struct S{ int len; long long tot; long long sqtot; }; using F = int; S op(S l, S r){ return S{l.len + r.len, l.tot + r.tot, l.sqtot + r.sqtot}; } S e(){ return S{0, 0, 0}; } S mapping(F l, S r){ return S{r.len, r.tot + l * r.len, r.sqtot + 2 * r.tot * l + r.len * l * l}; } F composition(F l, F r){ return l + r; } F id(){ return 0; } int main(void){ int n; cin >> n; vector A(n); int a; for(int i = 0; i < n; i++){ cin >> a; A[i] = S{1, a, a * a}; } lazy_segtree seg(A); int Q; cin >> Q; int t, l, r, x; while(Q--){ cin >> t >> l >> r; if(t == 1){ cin >> x; seg.apply(l - 1, r, x); } else{ auto ans = seg.prod(l - 1, r); cout << ans.sqtot << "\n"; } } }