#include #include using namespace std; typedef long long ll; int N; ll T[100001]; int M; int L[100001]; int R[100001]; ll D[100001]; vector node; ll sz; void init(int index,int val) { int i = index + sz - 1; node[i] += val; while(i > 0) { i = (i - 1) / 2; node[i] = max(node[i * 2 + 1],node[i * 2 + 2]); } } ll update(int a,int b,int k,int l,int r,int d) { if(r <= a || b <= l) return node[k]; if(a <= l && r <= b) { node[k] += d; return node[k]; } ll vl = update(a,b,2 *k + 1,l,(l + r) / 2,d); ll vr = update(a,b,2 * k + 2,(l + r) / 2,r,d); ll v = max(vl,vr); node[k] = max(node[k],v); return node[k]; } ll getTime(int a,int b,int k,int l,int r) { if(r <= a || b <= l) return -1; if(a <= l && r <= b) { return node[k]; } ll vl = getTime(a,b,2 *k + 1,l,(l + r) / 2); ll vr = getTime(a,b,2 * k + 2,(l + r) / 2,r); return max(vl,vr); } int main() { cin >> N; sz = 1; while(sz < N - 1) sz *= 2; node.resize(2 * sz - 1,0); for(int i = 0;i < N - 1 ;i++) { cin >> T[i]; init(i,T[i] + (N - i - 1) * 3); } cin >> M; for(int i = 1;i <= M;i++) { cin >> L[i] >> R[i] >> D[i]; } for(int i = 1;i <= M;i++) { int l = L[i]; int r = R[i]; ll d = D[i]; update(l - 1,r - 1 + 1,0,0,sz,d); cout << getTime(0,N - 1,0,0,sz)<< endl; } return 0; }