import std.conv, 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(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = cast(int)(as.length); for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; } int lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a < val)); } int upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a <= val)); } // -=- ==- -== === len alias P = Tuple!(long, long, long, long, int); P mul(in P a, in P b) { if (a[4] == 0) return b; if (b[4] == 0) return a; return P(max(a[0], b[0], a[2] + b[1]), max(a[1], a[3] + b[1]), max(b[2], a[2] + b[3]), a[3] + b[3], a[4] + b[4]); } class SegmentTree { int n; P[] prod; this(long[] ini) { const n_ = cast(int)(ini.length); for (n = 1; n < n_; n <<= 1) {} prod = new P[n << 1]; foreach (i; 0 .. n_) { prod[n + i] = P(ini[i], ini[i], ini[i], ini[i], 1); } foreach_reverse (a; 0 .. n) { prod[a] = mul(prod[a << 1], prod[a << 1 | 1]); } } void update(int a, long val) { prod[a += n] = P(val, val, val, val, 1); for (; (a >>= 1); ) { prod[a] = mul(prod[a << 1], prod[a << 1 | 1]); } } P rangeProd(int a, int b) { P retL, retR; for (a += n, b += n; a <= b; a >>= 1, b >>= 1) { if ( a & 1) retL = mul(retL, prod[a++]); if (~b & 1) retR = mul(prod[b--], retR); } return mul(retL, retR); } } enum INF = 10L^^18; void main() { try { for (; ; ) { const N = readInt(); const Q = readInt(); auto A = new long[N]; foreach (i; 0 .. N) { A[i] = readLong(); } auto seg = new SegmentTree(A); foreach (q; 0 .. Q) { const type = readToken(); switch (type) { case "set": { const i = readInt() - 1; const x = readLong(); seg.update(i, x); } break; case "max": { const l1 = readInt() - 1; const l2 = readInt(); const r1 = readInt() - 1; const r2 = readInt(); int[] xs = [l1, l2, r1, r2]; xs = xs.sort.uniq.array; const len = cast(int)(xs.length) - 1; auto ps = new P[len]; foreach (j; 0 .. len) { ps[j] = seg.rangeProd(xs[j], xs[j + 1] - 1); } debug { writeln("xs = ", xs); writeln("ps = ", ps); } long ans = -INF; foreach (i; 0 .. len) foreach (j; i .. len) { if (l1 <= xs[i] && xs[i + 1] <= l2 && r1 <= xs[j] && xs[j + 1] <= r2) { if (i == j) { chmax(ans, ps[i][0]); } else { chmax(ans, ps[i][2] + ps[i + 1 .. j].fold!"a + b[3]"(0L) + ps[j][1]); } } } writeln(ans); } break; default: assert(false); } } } } catch (EOFException e) { } }