#line 2 "/home/sakflat/CP/_library/cpp/template/template.cpp" //yukicoder@cpp17 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; using P = pair; const ll MOD = 998244353; const ll MODx = 1000000007; const int INF = (1<<30)-1; const ll LINF = (1LL<<62LL)-1; const double EPS = (1e-10); P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}}; P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}}; template vector make_vector(size_t a, T b) { return vector(a, b); } template auto make_vector(size_t a, Ts... ts) { return vector(a, make_vector(ts...)); } /* 確認ポイント cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる 計算量は変わらないが楽できるシリーズ min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる */ /* function corner below */ /* Function corner above */ /* comment outed because can cause bugs __attribute__((constructor)) void initial() { cin.tie(0); ios::sync_with_stdio(false); } */ #line 2 "/home/sakflat/CP/_library/cpp/template/basic.cpp" #line 1 "/home/sakflat/CP/_library/cpp/data-structure/segment-tree/lazy-add-segment-tree.cpp" template< typename T, typename F> struct LazySegmentTree{ private: int n; vector node,lazy; vector lazyTrigger; F f; T initer; public: LazySegmentTree(int n_, F f, T initer) : f(f),initer(initer) { n = 1; while(n < n_)n*=2; node.resize(2*n-1, initer); lazy.resize(2*n-1, 0); lazyTrigger.resize(2*n-1, false); } LazySegmentTree(int n_, F f, T initer, vector base) : f(f),initer(initer) { n = 1; while(n < n_)n*=2; node.resize(2*n-1, initer); set(base); lazy.resize(2*n-1, 0); lazyTrigger.resize(2*n-1, false); } void set(vector base){ int x = 1; while(x < n)x *= 2; x--; for(int i = 0; base.size() > i; i++){ node[i+x] = base[i]; } for(int i = x-1; 0 <= i; i--){ node[i] = f(node[i*2+1], node[i*2+2]); } } void eval(int k, int l, int r){ if(lazyTrigger[k]){ node[k] += lazy[k]/(r-l+1); if(r-l >= 1){ lazy[k*2+1] += lazy[k]/2; lazyTrigger[k*2+1] = true; lazy[k*2+2] += lazy[k]/2; lazyTrigger[k*2+2] = true; } lazy[k] = 0; lazyTrigger[k] = false; } } //TODO: update -> apply(such as update and add) void add(int a,int b, T x, int k = 0, int l = 0, int r = -1){ if(r < 0) r = n-1; eval(k, l, r); if(b < l || r < a){ return; } if(a <= l && r <= b){ lazy[k] = x*((r-l+1)); lazyTrigger[k] = true; eval(k, l, r); }else{ add(a,b,x,2*k+1, l, (l+r)/2); add(a,b,x,2*k+2,(l+r)/2+1,r); node[k] = f(node[k*2+1],node[k*2+2]); } } T getf(int a,int b, int k=0, int l=0, int r=-1){ if(r < 0){ r = n-1; } if(r < a || b < l){ return (1LL<<61); } eval(k,l,r); if(a <= l && r <= b){ return node[k]; } T vl = getf(a,b,2*k+1,l,(l+r)/2); T vr = getf(a,b,2*k+2,(l+r)/2+1,r); return f(vl,vr); } void debug(){ int nw = 1; int curr = 1; cout << "---begin---" << endl; for(int i = 0; 2*n-1 > i; i++){ cout << "(" << node[i] << ", " << lazy[i] << " (" << lazyTrigger[i] << ")) "; if(nw == curr)cout << endl,nw *= 2, curr=1; else curr++; } cout << "---end---" << endl; } }; template LazySegmentTree get_lazy_segment_tree(int N, const F &f, T initer){ return LazySegmentTree{N,f,initer}; } template LazySegmentTree get_lazy_segment_tree(int N, const F &f, T initer, vector base){ return LazySegmentTree(N, f, initer, base); } int main(){ int n;cin>>n; vector A(n); for(int i = 0; n > i; i++)cin>>A[i]; auto ST = get_lazy_segment_tree(n, [](long long a, long long b){return min(a,b);}, 0LL, A); int q;cin>>q; for(int i = 0; q > i; i++){ int k;cin>>k; if(k == 1){ int l,r;long long c;cin>>l>>r>>c;l--;r--; ST.add(l,r,c); }else{ int l,r,c;cin>>l>>r>>c;l--;r--; cout << ST.getf(l, r) << endl; } } return 0; }