#include <cstdio>
#include <algorithm>
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <set>
#include <cassert>
#include <queue>
using namespace std;
#define rank XBOCT4
#define right solo322
#define y1 dread1
#define left hohohaha
const double PI = acos(-1.0);
const int MD = 1000000000 + 7;
const long long INF = 1e18;
struct Node {
long long best;
long long sumStartPlus, sumStartMinus, sumEndPlus, sumEndMinus;
long long maxStartPlus, maxStartMinus, maxEndPlus, maxEndMinus;
int cnt;
bool flag;
Node(long long value) {
flag = true;
best = value;
maxStartPlus = value;
maxStartMinus = -value;
maxEndMinus = -INF;
maxEndPlus = value;
sumStartPlus = value;
sumStartMinus = -value;
sumEndPlus = value;
sumEndMinus = -INF;
cnt = 1;
}
Node() {}
};
inline Node combine(Node left, Node right) {
Node res;
if (!left.flag && !right.flag) {
res.flag = false;
return res;
}
if (!left.flag) {
return right;
}
if (!right.flag) {
return left;
}
res.flag = true;
res.cnt = left.cnt + right.cnt;
res.best = max(left.best, right.best);
res.best = max(res.best, max(left.maxEndMinus + right.maxStartPlus, left.maxEndPlus + right.maxStartMinus));
res.maxStartMinus = max(left.maxStartMinus, left.sumStartMinus + ((left.cnt % 2 == 0) ? right.maxStartMinus : right.maxStartPlus));
res.maxStartPlus = max(left.maxStartPlus , left.sumStartPlus + ((left.cnt % 2 == 0) ? right.maxStartPlus : right.maxStartMinus));
res.maxEndMinus = max(right.maxEndMinus , right.sumEndMinus + ((right.cnt % 2 == 0) ? left.maxEndMinus : left.maxEndPlus));
res.maxEndPlus = max(right.maxEndPlus , right.sumEndPlus + ((right.cnt % 2 == 0) ? left.maxEndPlus : left.maxEndMinus));
res.sumEndMinus = right.sumEndMinus + ((right.cnt % 2 == 0) ? left.sumEndMinus : left.sumEndPlus);
res.sumEndPlus = right.sumEndPlus + ((right.cnt % 2 == 0) ? left.sumEndPlus : left.sumEndMinus);
res.sumStartMinus = left.sumStartMinus + ((left.cnt % 2 == 0) ? right.sumStartMinus : right.sumStartPlus);
res.sumStartPlus = left.sumStartPlus + ((left.cnt % 2 == 0) ? right.sumStartPlus : right.sumStartMinus);
return res;
}
Node f[400333];
int n, sz;
Node get(int v, int tl, int tr, int l, int r) {
if (l > tr || tl > r) {
Node tmp;
tmp.flag = false;
return tmp;
}
if (l <= tl && r >= tr) {
return f[v];
}
int c =(tl + tr) / 2;
return combine(get(v * 2, tl, c, l, r), get(v * 2 + 1, c + 1, tr, l , r));
}
int main() {
ios_base::sync_with_stdio(false);
cin >> n;
sz = 1;
while (sz < n) {
sz += sz;
}
for (int i = 1; i <= n; i++) {
int value;
cin >> value;
f[i + sz - 1] = Node(value);
}
for (int i = n + 1; i <= sz; i++) {
f[i + sz - 1].flag = false;
}
for (int i = sz - 1; i > 0; i--) {
f[i] = combine(f[i * 2], f[i * 2 + 1]);
}
int q;
cin >> q;
while (q--) {
char c;
int l, r;
cin >> c >> l >> r;
if (c != 'Q') {
l = l + sz - 1;
f[l] = Node(r);
l /= 2;
while (l > 0) {
f[l] = combine(f[l * 2], f[l * 2 + 1]);
l /= 2;
}
} else {
cout << get(1, 1, sz, l, r).best << "\n";
}
}
return 0;
}
I2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y21hdGg+CiNpbmNsdWRlIDxtYXA+CiNpbmNsdWRlIDxzZXQ+CiNpbmNsdWRlIDxjYXNzZXJ0PgojaW5jbHVkZSA8cXVldWU+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgojZGVmaW5lIHJhbmsgWEJPQ1Q0CiNkZWZpbmUgcmlnaHQgc29sbzMyMgojZGVmaW5lIHkxIGRyZWFkMQojZGVmaW5lIGxlZnQgaG9ob2hhaGEKCmNvbnN0IGRvdWJsZSBQSSA9IGFjb3MoLTEuMCk7CmNvbnN0IGludCBNRCA9IDEwMDAwMDAwMDAgKyA3Owpjb25zdCBsb25nIGxvbmcgSU5GID0gMWUxODsKc3RydWN0IE5vZGUgewogICAgbG9uZyBsb25nIGJlc3Q7CiAgICBsb25nIGxvbmcgc3VtU3RhcnRQbHVzLCBzdW1TdGFydE1pbnVzLCBzdW1FbmRQbHVzLCBzdW1FbmRNaW51czsKICAgIGxvbmcgbG9uZyBtYXhTdGFydFBsdXMsIG1heFN0YXJ0TWludXMsIG1heEVuZFBsdXMsIG1heEVuZE1pbnVzOwogICAgaW50IGNudDsKICAgIGJvb2wgZmxhZzsKICAgIE5vZGUobG9uZyBsb25nIHZhbHVlKSB7CiAgICAgICAgZmxhZyAgICAgICAgICA9ICB0cnVlOwogICAgICAgIGJlc3QgICAgICAgICAgPSAgdmFsdWU7CiAgICAgICAgbWF4U3RhcnRQbHVzICA9ICB2YWx1ZTsKICAgICAgICBtYXhTdGFydE1pbnVzID0gLXZhbHVlOwogICAgICAgIG1heEVuZE1pbnVzICAgPSAtSU5GOwogICAgICAgIG1heEVuZFBsdXMgICAgPSAgdmFsdWU7CiAgICAgICAgc3VtU3RhcnRQbHVzICA9ICB2YWx1ZTsKICAgICAgICBzdW1TdGFydE1pbnVzID0gLXZhbHVlOwogICAgICAgIHN1bUVuZFBsdXMgICAgPSAgdmFsdWU7CiAgICAgICAgc3VtRW5kTWludXMgICA9IC1JTkY7CiAgICAgICAgY250ICAgICAgICAgICA9ICAxOwogICAgfQoKICAgIE5vZGUoKSB7fQoKfTsKCmlubGluZSBOb2RlIGNvbWJpbmUoTm9kZSBsZWZ0LCBOb2RlIHJpZ2h0KSB7CiAgICBOb2RlIHJlczsKICAgIGlmICghbGVmdC5mbGFnICYmICFyaWdodC5mbGFnKSB7CiAgICAgICAgcmVzLmZsYWcgPSBmYWxzZTsKICAgICAgICByZXR1cm4gcmVzOwogICAgfQogICAgaWYgKCFsZWZ0LmZsYWcpIHsKICAgICAgICByZXR1cm4gcmlnaHQ7CiAgICB9CiAgICBpZiAoIXJpZ2h0LmZsYWcpIHsKICAgICAgICByZXR1cm4gbGVmdDs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N6ID0gMTsKICAgIHdoaWxlIChzeiA8IG4pIHsKICAgICAgICBzeiArPSBzejsKICAgIH0KICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IG47IGkrKykgewogICAgICAgIGludCB2YWx1ZTsKICAgICAgICBjaW4gPj4gdmFsdWU7CiAgICAgICAgZltpICsgc3ogLSAxXSA9IE5vZGUodmFsdWUpOwogICAgfQogICAgZm9yIChpbnQgaSA9IG4gKyAxOyBpIDw9IHN6OyBpKyspIHsKICAgICAgICBmW2kgKyBzeiAtIDFdLmZsYWcgPSBmYWxzZTsKICAgIH0KICAgIGZvciAoaW50IGkgPSBzeiAtIDE7IGkgPiAwOyBpLS0pIHsKICAgICAgICBmW2ldID0gY29tYmluZShmW2kgKiAyXSwgZltpICogMiArIDFdKTsKICAgIH0KICAgIGludCBxOwogICAgY2luID4+IHE7CiAgICB3aGlsZSAocS0tKSB7CiAgICAgICAgY2hhciBjOwogICAgICAgIGludCBsLCByOwogICAgICAgIGNpbiA+PiBjID4+IGwgPj4gcjsKICAgICAgICBpZiAoYyAhPSAnUScpIHsKICAgICAgICAgICAgbCA9IGwgKyBzeiAtIDE7CiAgICAgICAgICAgIGZbbF0gPSBOb2RlKHIpOwogICAgICAgICAgICBsIC89IDI7CiAgICAgICAgICAgIHdoaWxlIChsID4gMCkgewogICAgICAgICAgICAgICAgZltsXSA9IGNvbWJpbmUoZltsICogMl0sIGZbbCAqIDIgKyAxXSk7CiAgICAgICAgICAgICAgICBsIC89IDI7CiAgICAgICAgICAgIH0KICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBjb3V0IDw8IGdldCgxLCAxLCBzeiwgbCwgcikuYmVzdCA8PCAiXG4iOwogICAgICAgIH0KICAgIH0KICAgIHJldHVybiAwOwp9