#include using namespace std; #define rep(i, n) for(int i = 0; i < n; i++) #define rep2(i, x, n) for(int i = x; i <= n; i++) #define rep3(i, x, n) for(int i = x; i >= n; i--) #define elif else if #define sp(x) fixed << setprecision(x) #define pb push_back #define eb emplace_back #define all(x) x.begin(), x.end() #define sz(x) (int)x.size() using ll = long long; using pii = pair; using pil = pair; using pli = pair; using pll = pair; const int MOD = 1000000007; //const int MOD = 998244353; const int inf = (1<<30)-1; const ll INF = (1LL<<60)-1; const double pi = acos(-1.0); const double EPS = 1e-10; template bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;}; template bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;}; template struct Starry_Sky_Tree{ vector seg; vector lazy; const Monoid e1; const Operator_Monoid e2; const int n; Monoid f(const Monoid &a, const Monoid &b) const {return min(a, b);} Monoid g(const Monoid &a, const Operator_Monoid &b) const {return a+b;} Operator_Monoid h(const Operator_Monoid &a, const Operator_Monoid &b) const {return a+b;} Starry_Sky_Tree(int N, const Monoid &e1, const Operator_Monoid &e2) : e1(e1), e2(e2), n(1<<(32-__builtin_clz(N-1))){ seg.assign(2*n, e1), lazy.assign(2*n, e2); } void set(int i, const Monoid &x) {seg[n+i] = x;} void build(){ rep3(i, n-1, 1) seg[i] = f(seg[2*i], seg[2*i+1]); } void init(int N, const Monoid &x){ rep(i, N) set(i, x); build(); } void eval(int i, int l, int r){ if(lazy[i] != e2){ //seg[i] = g(seg[i], lazy[i]*(r-l)); seg[i] = g(seg[i], lazy[i]); if(r-l > 1){ lazy[2*i] = h(lazy[2*i] ,lazy[i]); lazy[2*i+1] = h(lazy[2*i+1], lazy[i]); } lazy[i] = e2; } } void add(int a, int b, const Operator_Monoid &x, int i, int l, int r){ eval(i, l, r); if(a >= r || b <= l) return; if(a <= l && r <= b){ lazy[i] = h(lazy[i], x); eval(i, l, r); } else{ add(a, b, x, 2*i, l, (l+r)/2); add(a, b, x, 2*i+1, (l+r)/2, r); seg[i] = f(seg[2*i], seg[2*i+1]); } } void add(int a, int b, const Operator_Monoid &x) {add(a, b, x, 1, 0, n);} Monoid query(int a, int b, int i, int l, int r){ eval(i, l, r); if(a >= r || b <= l) return e1; if(a <= l && r <= b) return seg[i]; Monoid vl = query(a, b, 2*i, l, (l+r)/2); Monoid vr = query(a, b, 2*i+1, (l+r)/2, r); return f(vl, vr); } Monoid query(int a, int b) {return query(a, b, 1, 0, n);} void update(int i, int l, int r){ seg[i] = g(seg[i], lazy[i]); if(r-l > 1){ lazy[2*i] = h(lazy[2*i], lazy[i]); lazy[2*i+1] = h(lazy[2*i+1], lazy[i]); update(2*i, l, (l+r)/2); update(2*i+1, (l+r)/2, r); } lazy[i] = e2; } void update() {update(1, 0, n);} Monoid operator [] (int i) const {return seg[n+i];} void clear(){ fill(all(seg), e1), fill(all(lazy), e2); } }; int main(){ int N; cin >> N; ll a[N]; rep(i, N) cin >> a[i]; Starry_Sky_Tree seg(N, INF, 0); rep(i, N) seg.set(i, a[i]); seg.build(); int Q; cin >> Q; while(Q--){ int k, l, r; ll c; cin >> k >> l >> r >> c; l--; if(k == 1) seg.add(l, r, c); else cout << seg.query(l, r) << endl; } }