#include #define LLI long long int #define FOR(v, a, b) for(LLI v = (a); v < (b); ++v) #define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v) #define REP(v, n) FOR(v, 0, n) #define REPE(v, n) FORE(v, 0, n) #define REV(v, a, b) for(LLI v = (a); v >= (b); --v) #define ALL(x) (x).begin(), (x).end() #define RALL(x) (x).rbegin(), (x).rend() #define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it) #define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it) #define EXIST(c,x) ((c).find(x) != (c).end()) #define fst first #define snd second #define popcount __builtin_popcount #define UNIQ(v) (v).erase(unique(ALL(v)), (v).end()) #define bit(i) (1LL<<(i)) #ifdef DEBUG #include #else #define dump(...) ((void)0) #endif #define gcd __gcd using namespace std; template constexpr T lcm(T m, T n){return m/gcd(m,n)*n;} template void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost< istream& operator>>(istream &is, vector &v){for(auto &a : v) is >> a; return is;} template bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);} template bool chmax(T &a, const U &b){return (a void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);} struct Init{ Init(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12); cerr << fixed << setprecision(12); } }init; template class LazySegmentTree{ const int depth, size, hsize; const T e1; const TFunc f1; const U e2; const UFunc f2; const Op g; // g(T, U, int) -> T std::vector data; std::vector lazy; inline void propagate(int i, int l){ if(lazy[i] == e2) return; if(i < size/2){ lazy[i*2+1] = f2(lazy[i], lazy[i*2+1]); lazy[i*2+2] = f2(lazy[i], lazy[i*2+2]); } data[i] = g(data[i], lazy[i], l); lazy[i] = e2; } inline T update_aux(int i, int l, int r, int s, int t, const U &x){ propagate(i,r-l); if(r <= s || t <= l) return data[i]; else if(s <= l && r <= t){ lazy[i] = f2(x, lazy[i]); propagate(i,r-l); return data[i]; } else return data[i] = f1(update_aux(i*2+1,l,(l+r)/2,s,t,x), update_aux(i*2+2,(l+r)/2,r,s,t,x)); } inline T query_aux(int i, int l, int r, int x, int y){ propagate(i,r-l); if(r <= x || y <= l) return e1; else if(x <= l && r <= y) return data[i]; else return f1(query_aux(i*2+1,l,(l+r)/2,x,y), query_aux(i*2+2,(l+r)/2,r,x,y)); } public: LazySegmentTree(){} LazySegmentTree(int n, const T &e1, const TFunc &f1, const U &e2, const UFunc &f2, const Op &g): depth(n > 1 ? 32-__builtin_clz(n-1) + 1 : 1), size((1 << depth) - 1), hsize(size / 2 + 1), e1(e1), f1(f1), e2(e2), f2(f2), g(g), data(size + 1, e1), lazy(size + 1, e2) {} inline void update(int s, int t, const U &x){ update_aux(0,0,hsize,s,t,x); } inline void update_at(int i, const U &x){ update(i, i+1, x); } inline T get(int x, int y){ return query_aux(0,0,hsize,x,y); } inline T at(int x){ return get(x, x+1); } inline void init(const T &val){ data.assign(size, e1); lazy.assign(size, e2); for(int i = size/2; i < size; ++i){ data[i] = val; } for(int i = size/2-1; i >= 0; --i){ data[i] = f1(data[i*2+1], data[i*2+2]); } } inline void init_with_vector(const std::vector &val){ data.assign(size, e1); lazy.assign(size, e2); for(int i = size/2; i < size; ++i){ if(i-size/2 < (int)val.size()) data[i] = val[i-size/2]; } for(int i = size/2-1; i >= 0; --i){ data[i] = f1(data[i*2+1], data[i*2+2]); } } inline void debug(){ #ifdef DEBUG std::cerr << "{"; for(int i = 0; i < hsize; ++i){ if(i) std::cerr << ","; std::cerr << at(i); } std::cerr << "}" << std::endl; #endif } }; template auto make_segment_tree_range_add_range_max(int size, const T &e1, const U &e2){ auto f1 = [](const auto &a, const auto &b){return std::max(a, b);}; auto f2 = [](const auto &a, const auto &b){return a + b;}; auto g = [](const auto &a, const auto &b, int l){return a + b;}; return LazySegmentTree(size, e1, f1, e2, f2, g); } int main(){ int N; while(cin >> N){ auto seg = make_segment_tree_range_add_range_max(N-1, 0, 0); vector T(N-1); cin >> T; REP(i,N-1){ T[i] += 3 * (N-1-i); } seg.init_with_vector(T); int M; cin >> M; REP(i,M){ int L, R, D; cin >> L >> R >> D; --L, --R; seg.update(L, R+1, D); auto ans = seg.get(0, N-1); cout << ans << endl; } } return 0; }