#include #define FOR(i,a,b) for (int i=(a);i<(b);i++) #define FORR(i,a,b) for (int i=(a);i>=(b);i--) #define pb push_back #define pcnt __builtin_popcount #define show(x) cout<<#x<<" = "< pii; typedef vector vi; typedef vector vvi; typedef vector vpii; typedef set si; typedef pair pll; typedef vector vl; typedef vector vvl; typedef vector vpll; typedef set sl; typedef __int128_t lll; typedef pair plll; typedef vector vlll; templatestring join(vector&v) {stringstream s;FOR(i,0,sz(v))s<<' '<b)swap(a,b);for(;a>0;b%=a,swap(a,b));return b;} int modpow(ll a,ll n,int m){if(a==0)return a;ll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(int)p;} void dout(double d){printf("%.12f\n",d);} const int iinf = 1e9; const ll linf = 1e18; const int mod = 1e9+7; const double pi = acos(-1); const double eps = 1e-10; const int N = 1e5; struct SegTreeAdd{ typedef ll T; const T e_merge = -linf; const T e_add = 0; T merge(T a, T b){return max(a, b);} T add(T a, T b){return a+b;} T prod(int a, T b){return b;} //################################################### int n; vector d, s; void init(int m){ n = 1<<(32-__builtin_clz(m-1)); d.resize(2*n-1); s.resize(2*n-1); fill(d.begin(), d.end(), e_merge); fill(s.begin(), s.end(), e_add); } void init(vector&v){ init(v.size()); for(int j=0; j=0; j--) d[j] = merge(d[j*2+1], d[j*2+2]); } void update(int k,T v){ if(k<0) return; query(k, k+1); k += n-1; d[k] = v; while(k){ k = (k-1)/2; d[k] = merge(d[k*2+1], d[k*2+2]); } } T _section_add(int a,int b,int k,int l,int r, T&v){ if(r<=a||b<=l){ }else if(a<=l&&r<=b){ s[k] = add(s[k], v); d[k] = add(d[k], prod(r-l, v)); }else{ s[k*2+1] = add(s[k*2+1], s[k]); d[k*2+1] = add(d[k*2+1], prod((r-l)/2, s[k])); s[k*2+2] = add(s[k*2+2], s[k]); d[k*2+2] = add(d[k*2+2], prod((r-l)/2, s[k])); s[k] = e_add; d[k] = merge(_section_add(a, b, k*2+1, l, (l+r)/2, v), _section_add(a, b, k*2+2, (l+r)/2, r, v)); } return d[k]; } void section_add(int a, int b, T&v){ _section_add(a, b, 0, 0, n, v); } T _query(int a,int b,int k,int l,int r){ if(r<=a||b<=l) return e_merge; if(a<=l&&r<=b){ return d[k]; }else{ s[k*2+1] = add(s[k*2+1], s[k]); d[k*2+1] = add(d[k*2+1], prod((r-l)/2, s[k])); s[k*2+2] = add(s[k*2+2], s[k]); d[k*2+2] = add(d[k*2+2], prod((r-l)/2, s[k])); s[k] = e_add; return merge(_query(a, b, k*2+1, l, (l+r)/2), _query(a, b, k*2+2, (l+r)/2, r)); } } T query(int a,int b){ return _query(a, b, 0, 0, n); } }; ll n, m, l, r, d; vl t; SegTreeAdd seg; main(){ cin.tie(0); ios::sync_with_stdio(false); cin >> n; FOR(i, 0, n-1){ cin >> d; t.pb(d + (n-1-i)*3); } seg.init(t); cin >> m; FOR(i, 0, m){ cin >> l >> r >> d; seg.section_add(l-1, r, d); cout << seg.query(0, n-1) << "\n"; } return 0; }