inline void _link(int p, int sn, int t) { Node[p].child[sn] = t; Node[t].parent = p; Node[t].sn = sn; }
inline void _rotate(int t) { int p = Node[t].parent; int sn = Node[t].sn; int osn = sn ^ 1; _link(p, sn, Node[t].child[osn]); _link(Node[p].parent, Node[p].sn, t); _link(t, osn, p); _pushUp(p); }
void _splay(int t, int p, int &root) { while (Node[t].parent != p) { int pp = Node[t].parent; if (Node[pp].parent != p) Node[pp].sn == Node[t].sn ? _rotate(pp) : _rotate(t); _rotate(t); } _pushUp(t); if (0 == p) root = t; }
int _kth(int root, int index) { int son = Node[root].child[LEFT]; int ss = son ? Node[son].size : 0; if (ss == index) return root; return index }
void build(int &t, int parent, int sn, int s, int e, value_t const a[]) { int mid = (s + e) >> 1; t = _newNode(); Node[t].parent = parent; Node[t].value = a[mid]; Node[t].sn = sn; if (mid > s) build(Node[t].child[LEFT], t, LEFT, s, mid - 1, a); if (mid _pushUp(t); }
int query(int &root, int s, int e) { int t = _kth(root, s - 1); _splay(t, 0, root); t = _kth(root, e + 1); _splay(t, root, root); return Node[Node[t].child[LEFT]].peak; }
void modify(int &root, int idx, value_t v) { int t = _kth(root, idx); _splay(t, 0, root); Node[t].value = v; if (Node[t].peak }
int N, M; int A[SIZE] = {0};
bool read() { if (EOF == scanf("%d%d", &N, &M)) return false; for (int i = 1; i <= N; ++i) scanf("%d", A + i); A[N + 1] = 0; return true; }
int main() { while (read()) { init(); build(Root, 0, 0, 0, N + 1, A); while (M--) { char cmd[3]; int a, b; scanf("%s%d%d", cmd, &a, &b); if ('Q' == *cmd) { printf("%d\n", query(Root, a, b)); } else { modify(Root, a, b); } } } return 0; } ```