#include #include using namespace std; using namespace atcoder; struct Fast { Fast() { std::cin.tie(0); ios::sync_with_stdio(false); } } fast; #define rep(i, a, b) for (int i = (a); i < (int)(b); i++) #define rrep(i, a, b) for (int i = (int)(b)-1; i >= (a); i--) #define Yn(b) cout << ((b) ? "Yes" : "No") << "\n"; #define ll long long template bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } using S = array; using F = array; S e() { return {0, 0, 0}; } F id() { return {1, 0, 0, 0, 1, 0, 0, 0, 1}; } S op(S x, S y) { S z{}; rep(i, 0, 3) z[i] = x[i] + y[i]; return z; } S mapping(F f, S x) { S y{}; rep(i, 0, 3) rep(j, 0, 3) y[i] += f[3 * i + j] * x[j]; return y; } F composition(F f, F g) { F h{}; rep(i, 0, 3) rep(j, 0, 3) rep(k, 0, 3) h[3 * i + j] += f[3 * i + k] * g[3 * k + j]; return h; } int main() { int n, q; cin >> n; vector a(n); rep(i, 0, n) cin >> a[i]; cin >> q; vector b(n); rep(i, 0, n) b[i] = {1, a[i], a[i] * a[i]}; lazy_segtree seg(b); while (q--) { int type; cin >> type; if (type == 1) { int l, r; ll x; cin >> l >> r >> x; seg.apply(l - 1, r, {1, 0, 0, x, 1, 0, x * x, 2 * x, 1}); } if (type == 2) { int l, r; cin >> l >> r; cout << seg.prod(l - 1, r)[2] << "\n"; } } }