using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.IO; using System.Text; using System.Diagnostics; class Program { static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; static Scan sc = new Scan(); const long LM = (long)1e18; static void Main() { int n, q; sc.Multi(out n, out q); var a = sc.LongArr; sg = new Segtree(n, node.compose, node.ex); for (int i = 0; i < n; i++) sg.assign(i, new node(a[i])); sg.all_update(); for (int _ = 0; _ < q; _++) { var inp = sc.StrArr; if (inp[0] == "set") { int i = int.Parse(inp[1]) - 1; long x = long.Parse(inp[2]); sg.update(i, new node(x)); } else if (inp[0] == "max") { int l1 = int.Parse(inp[1]) - 1; int l2 = int.Parse(inp[2]); int r1 = int.Parse(inp[3]) - 1; int r2 = int.Parse(inp[4]); if (l1 >= l2 || r1 >= r2 || l1 >= r2) throw new Exception(); l2 = Math.Min(l2, r2); r1 = Math.Max(l1, r1); if (l2 <= r1) Prt(calc(l1, l2, r1, r2)); else Prt(Math.Max(calc(r1, l2), Math.Max(calc(l1, l2, l2, r2), calc(l1, r1, r1, r2)))); } else throw new Exception(); } sw.Flush(); } static Segtree sg; static long calc(int l, int r) => sg.run(l, r).inmax; // l1 < l2 <= r1 < r2 static long calc(int l1, int l2, int r1, int r2) => sg.run(l1, l2).rmax + sg.run(r1, r2).lmax + (l2 == r1 ? 0 : sg.run(l2, r1).sum); class node { public readonly long lmax, rmax, inmax, sum; public node(long x) : this(x, x, x, x) {} public static readonly node ex = new node(-LM, -LM, -LM, 0); node(long lmax, long rmax, long inmax, long sum) { this.lmax = lmax; this.rmax = rmax; this.inmax = inmax; this.sum = sum; } public static node compose(node l, node r) => new node(Math.Max(l.lmax, l.sum + r.lmax), Math.Max(r.rmax, l.rmax + r.sum), Math.Max(Math.Max(l.inmax, r.inmax), l.rmax + r.lmax), l.sum + r.sum); } static void Prt(string a) => sw.WriteLine(a); static void Prt(IEnumerable a) => Prt(string.Join(" ", a)); static void Prt(params object[] a) => Prt(string.Join(" ", a)); } class Scan { public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public string Str => Console.ReadLine().Trim(); public int[] IntArr => StrArr.Select(int.Parse).ToArray(); public long[] LongArr => StrArr.Select(long.Parse).ToArray(); public double[] DoubleArr => StrArr.Select(double.Parse).ToArray(); public string[] StrArr => Str.Split(new[]{' '}, StringSplitOptions.RemoveEmptyEntries); bool eq() => typeof(T).Equals(typeof(U)); T ct(U a) => (T)Convert.ChangeType(a, typeof(T)); T cv(string s) => eq() ? ct(int.Parse(s)) : eq() ? ct(long.Parse(s)) : eq() ? ct(double.Parse(s)) : eq() ? ct(s[0]) : ct(s); public void Multi(out T a) => a = cv(Str); public void Multi(out T a, out U b) { var ar = StrArr; a = cv(ar[0]); b = cv(ar[1]); } public void Multi(out T a, out U b, out V c) { var ar = StrArr; a = cv(ar[0]); b = cv(ar[1]); c = cv(ar[2]); } public void Multi(out T a, out U b, out V c, out W d) { var ar = StrArr; a = cv(ar[0]); b = cv(ar[1]); c = cv(ar[2]); d = cv(ar[3]); } } class Segtree { int n, s, t; T[] tr; Func f; T exnum; // expect : f(ex, ex) = ex public Segtree(int m, Func f, T ex) { this.f = f; this.exnum = ex; n = 1; while (n < m) n <<= 1; tr = new T[(n << 1) - 1]; for (int i = 0; i < tr.Length; i++) tr[i] = ex; } public Segtree(int m, T ini, Func f, T ex) : this(m, f, ex) { for (int i = 0; i < m; ++i) assign(i, ini); all_update(); } public Segtree(int m, IList ini, Func f, T ex) : this(m, f, ex) { for (int i = 0; i < m; ++i) assign(i, ini[i]); all_update(); } public void assign(int j, T x) => tr[j + n - 1] = x; public void update(int j, T x) { assign(j, x); update(j); } public void update(int j) { int i = j + n - 1; while (i > 0) { i = i - 1 >> 1; tr[i] = f(tr[i << 1 | 1], tr[i + 1 << 1]); } } public void all_update() { for (int i = n - 2; i >= 0; i--) tr[i] = f(tr[i << 1 | 1], tr[i + 1 << 1]); } public T look(int i) => tr[i + n - 1]; // [s, t) public T run(int s, int t) { this.s = s; this.t = t; return q(0, 0, n); } T q(int k, int l, int r) => r <= s || t <= l ? exnum : s <= l && r <= t ? tr[k] : f(q(k << 1 | 1, l, l + r >> 1), q(k + 1 << 1, l + r >> 1, r)); }