import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines class SegTree: def __init__(self, N, X_f, X_unit, X_commutative=False): self.N = N self.X_f = X_f self.X_unit = X_unit self.X = [self.X_unit] * (N + N) if X_commutative: self.fold = self._fold_commutative def build(self, seq): for i, x in enumerate(seq, self.N): self.X[i] = x for i in range(self.N - 1, 0, -1): self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1]) def set_val(self, i, x): i += self.N self.X[i] = x while i > 1: i >>= 1 self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1]) def fold(self, L, R): L += self.N R += self.N vL = vR = self.X_unit while L < R: if L & 1: vL = self.X_f(vL, self.X[L]) L += 1 if R & 1: R -= 1 vR = self.X_f(self.X[R], vR) L >>= 1 R >>= 1 return self.X_f(vL, vR) def _fold_commutative(self, L, R): L += self.N R += self.N v = self.X_unit while L < R: if L & 1: v = self.X_f(v, self.X[L]) L += 1 if R & 1: R -= 1 v = self.X_f(v, self.X[R]) L >>= 1 R >>= 1 return v X_unit = None def X_f(x, y): if x is None: return y if y is None: return x return (max(x[0], y[0], x[2] + y[1]), max(x[1], x[3] + y[1]), max(y[2], x[2] + y[3]), x[3] + y[3]) N, Q = map(int, readline().split()) A = map(int, readline().split()) seg = SegTree(N, X_f, X_unit) seg.build((x, x, x, x) for x in A) def range_max(L1, L2, R1, R2): R1 = max(L1, R1) L2 = min(L2, R2) if L2 < R1: mid = 0 if R1 == L2 + 1 else seg.fold(L2 + 1, R1)[3] return seg.fold(L1, L2 + 1)[2] + mid + seg.fold(R1, R2 + 1)[1] ret = -10**18 # R1 より左に左端がある if L1 < R1: ret = max(ret, seg.fold(L1, R1)[2] + seg.fold(R1, R2 + 1)[1]) # L2 以前に右端がある ret = max(ret, seg.fold(R1, L2 + 1)[0]) # L2 より右に右端がある if L2 < R2: ret = max(ret, seg.fold(R1, L2 + 1)[2] + seg.fold(L2 + 1, R2 + 1)[1]) return ret for query in readlines(): if query.startswith(b's'): i, x = map(int, query[4:].split()) seg.set_val(i - 1, (x, x, x, x)) else: print(range_max(*map(lambda x: int(x) - 1, query[4:].split())))