#include using namespace std; void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } #include using namespace atcoder; struct S { long long aa, a, len; }; S op(S a, S b) { return {a.aa + b.aa, a.a + b.a, a.len + b.len}; } S e() { return {0, 0, 0}; } S mapping(long long f, S x) { return {x.aa + 2 * f * x.a + f * f * x.len, x.a + f * x.len, x.len}; } long long composition(long long f, long long g) { return f + g; } long long id() { return 0; } int main() { fast_io(); int n; cin >> n; vector v(n); for (int i = 0; i < n; i++) { long long a; cin >> a; v[i] = {a * a, a, 1}; } lazy_segtree seg(v); int q; cin >> q; for (; q--;) { int type, l, r; cin >> type >> l >> r; l--; if (type == 1) { long long x; cin >> x; seg.apply(l, r, x); } if (type == 2) { cout << seg.prod(l, r).aa << "\n"; } } }