///@author Sycamore ///@date 9/17/2017 ///@link http://acm.hdu.edu.cn/showproblem.php?pid=1754 #includeusing namespace std; const int MAXN = 200000 + 5; int val[MAXN]; struct node { int l, r, max_val; } ST[MAXN << 2]; void Build(int index, int l, int r) { ST[index].l = l; ST[index].r = r; if (l == r) ST[index].max_val = val[l]; else { int m = (l + r) >> 1; Build(index << 1, l, m); Build((index << 1) + 1, m + 1, r); ST[index].max_val = max(ST[index << 1].max_val, ST[(index << 1) + 1].max_val); } } void Update(int n, int index, int id)//top-down { if (id < ST[index].l || id > ST[index].r) return; if (ST[index].l == id && ST[index].r == id) { ST[index].max_val = n; return; } Update(n,index << 1, id); Update(n,(index << 1) + 1, id); ST[index].max_val = max(ST[index << 1].max_val, ST[(index << 1) + 1].max_val); } int Query(int l, int r, int index)//top-down { if (ST[index].l > r || ST[index].r = l && ST[index].r <= r)return ST[index].max_val; int m = (ST[index].l + ST[index].r) >> 1; if (r <= m)return Query(l, r, index << 1);//in the left interval if (l > m)return Query(l, r, (index << 1) + 1); return max(Query(l, m, index << 1), Query(m + 1, r, (index << 1) + 1)); } #define endl '\n' int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m; while (cin >> n >> m) { for (int i = 1; i <= n; i++)cin >> val[i]; Build(1, 1, n); char cmd; while (m--) { cin >> cmd; if (cmd == 'Q') { int l, r; cin >> l >> r; cout << Query(l, r, 1) << endl; } else { int a, id; cin >> id >> a; Update(a, 1, id); } } } return 0; }