import std.conv, std.functional, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.container, std.math, std.numeric, std.range, std.regex, std.typecons; import core.bitop; class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; } int readInt() { return readToken.to!int; } long readLong() { return readToken.to!long; } real readReal() { return readToken.to!real; } bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } } bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } } int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; } int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); } int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); } enum INF = 10L^^18; class SegmentTree { int n; long[] mx, add; this(long[] ini) { const n_ = cast(int)(ini.length); for (n = 1; n < n_; n <<= 1) {} mx = new long[n << 1]; add = new long[n << 1]; mx[] = -INF; add[] = 0; foreach (i; 0 .. n_) { mx[n + i] = ini[i]; } foreach_reverse (a; 1 .. n) { mx[a] = max(mx[a << 1], mx[a << 1 | 1]); } } // [a, b) private long query(int u, int x, int y, int a, int b, long val) { chmax(a, x); chmin(b, y); if (a >= b) { return -INF; } if (a == x && b == y) { mx[u] += val; add[u] += val; return mx[u]; } assert(u < n); const uL = u << 1 | 0; const uR = u << 1 | 1; const mid = (x + y) >> 1; if (add[u] != 0) { mx[uL] += add[u]; mx[uR] += add[u]; add[uL] += add[u]; add[uR] += add[u]; add[u] = 0; } const resL = query(uL, x, mid, a, b, val); const resR = query(uR, mid, y, a, b, val); mx[u] = max(mx[uL], mx[uR]); return max(resL, resR); } // [a, b] long query(int a, int b, long val) { return query(1, 0, n, a, b + 1, val); } } int N; long[] T; int M; int[] L, R; long[] D; void main() { try { for (; ; ) { N = readInt(); T = new long[N - 1]; foreach (i; 0 .. N - 1) { T[i] = readLong(); } M = readInt(); L = new int[M]; R = new int[M]; D = new long[M]; foreach (m; 0 .. M) { L[m] = readInt() - 1; R[m] = readInt() - 1; D[m] = readInt(); } auto ini = new long[N]; foreach (i; 0 .. N - 1) { ini[i] = T[i] + 3 * (N - 1 - i); } auto seg = new SegmentTree(ini); foreach (m; 0 .. M) { seg.query(L[m], R[m], D[m]); writeln(seg.mx[1]); } } } catch (EOFException e) { } }