#![allow(unused_imports)] use std::cmp::*; use std::collections::*; use std::io::Write; use std::ops::Bound::*; #[allow(unused_macros)] macro_rules! debug { ($($e:expr),*) => { #[cfg(debug_assertions)] $({ let (e, mut err) = (stringify!($e), std::io::stderr()); writeln!(err, "{} = {:?}", e, $e).unwrap() })* }; } fn main() { let n = read::(); let mut a = read_vec::(); let num_buckets = 1000; let bucket_width = 1000; let mut bucket_added = vec![0; num_buckets]; let mut bucket_min = vec![std::i64::MAX; num_buckets]; for i in 0..n { bucket_min[i / bucket_width] = min(a[i], bucket_min[i / bucket_width]); } let q = read::(); let mut queries = vec![]; for i in 0..q { let v = read_vec::(); let (k, l, r, c) = (v[0], v[1] as usize - 1, v[2] as usize - 1, v[3]); queries.push((k, l, r, c)); } for (k, l, r, c) in queries { if k == 1 { let mut tl = 0; let mut tr = bucket_width - 1; for bi in 0..num_buckets { if r < tl || l > tr { // Nothing } else if l <= tl && r >= tr { bucket_added[bi] += c; bucket_min[bi] += c; } else { for i in 0..bucket_width { if i + tl >= l && i + tl <= r { a[i + tl] += c; } } bucket_min[bi] = std::i64::MAX; for i in 0..bucket_width { if i + tl >= n { break; } bucket_min[bi] = min(a[i + tl] + bucket_added[bi], bucket_min[bi]); } } tl += bucket_width; tr += bucket_width; } } else { let mut tl = 0; let mut tr = bucket_width - 1; let mut ans = std::i64::MAX; for bi in 0..num_buckets { if r < tl || l > tr { // Nothing } else if l <= tl && r >= tr { ans = min(ans, bucket_min[bi]); } else { for i in 0..bucket_width { if i + tl >= l && i + tl <= r { if i + tl >= n { break; } ans = min(ans, a[i + tl] + bucket_added[bi]); } } } tl += bucket_width; tr += bucket_width; } println!("{}", ans); } } } fn read() -> T { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim().parse().ok().unwrap() } fn read_vec() -> Vec { read::() .split_whitespace() .map(|e| e.parse().ok().unwrap()) .collect() }