#include using namespace std; // RMQ + range_add struct RMQ { using value_type = long long; static value_type id() { return 1e18; } static value_type op(const value_type &l, const value_type &r) { return std::min(l, r); } }; // LeftHandSide struct LazyEval { using value_type = long long; static value_type op(const value_type &l, const value_type &r) { return l + r; } }; struct RangeUpdateRMQ { using Monoid = RMQ; using Update = LazyEval; using value_type = typename Monoid::value_type; using update_type = typename Update::value_type; static value_type evaluate(const update_type &update, const value_type &r) { return update + r; } }; int log2ceil(int n) { --n; n |= n >> 16; n |= n >> 8; n |= n >> 4; n |= n >> 2; n |= n >> 1; return n + 1; } template class SegmentTreeLazy { public: using Monoid = typename Struct::Monoid; using Update = typename Struct::Update; using value_type = typename Struct::value_type; using update_type = typename Struct::update_type; private: const int n; std::vector data; std::vector lazy; std::vector flag; void lazyset(int node, const update_type &update) { if (node < n) { if (flag[node]) { lazy[node] = Update::op(update, lazy[node]); } else { lazy[node] = update; flag[node] = true; } } data[node] = Struct::evaluate(update, data[node]); } void evaluate(int node) { if (!flag[node]) return; flag[node] = false; lazyset(node * 2 + 0, lazy[node]); lazyset(node * 2 + 1, lazy[node]); } void update_sub(int l, int r, int node, int lb, int ub, const update_type &update) { if (ub <= l || r <= lb) { return; } if (l <= lb && ub <= r) { lazyset(node, update); return; } evaluate(node); const int mid = (lb + ub) / 2; update_sub(l, r, node * 2 + 0, lb, mid, update); update_sub(l, r, node * 2 + 1, mid, ub, update); data[node] = Monoid::op(data[node * 2 + 0], data[node * 2 + 1]); } value_type query_sub(int l, int r, int node, int lb, int ub) { if (ub <= l || r <= lb) return Monoid::id(); if (l <= lb && ub <= r) { return data[node]; } evaluate(node); const int mid = (lb + ub) / 2; value_type lval = query_sub(l, r, node * 2 + 0, lb, mid); value_type rval = query_sub(l, r, node * 2 + 1, mid, ub); return Monoid::op(lval, rval); } public: SegmentTreeLazy(int count, const value_type &init = Monoid::id()) : n(log2ceil(count)), data(n * 2), lazy(n), flag(n, false) { fill(begin(data) + n, end(data), init); for (int i = n - 1; i >= 1; i--) { data[i] = Monoid::op(data[i * 2 + 0], data[i * 2 + 1]); } }; void update(int l, int r, const update_type &f) { update_sub(l, r, 1, 0, n, f); } value_type query(int l, int r) { return query_sub(l, r, 1, 0, n); } }; int main() { int N; cin >> N; vector A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } SegmentTreeLazy lazy(N, 0); for (int i = 0; i < N; i++) lazy.update(i, i + 1, A[i]); int Q; cin >> Q; for (int i = 0; i < Q; i++) { int k, l, r, c; cin >> k >> l >> r >> c; --l; if (k == 1) { lazy.update(l, r, c); } else { cout << lazy.query(l, r) << endl; } } }