---
# System prepended metadata

title: '[HDU-1754]'

---

# [HDU-1754]
```cpp=
#include<iostream>
#include<algorithm>
using namespace std;
#define N int(2e5 + 5)
static int mx[N << 2];
int n, m;
char c;
void pull(int x){
    mx[x] = max(mx[x<<1] , mx[x<<1|1]);
}
void build(int x, int l, int r){
    if (l == r){
        cin >> mx[x];
        return;
    }
    int mid = (l + r) / 2;
    build(x << 1, l, mid);
    build(x <<1 | 1, mid+1, r);
    pull(x);
}
int query(int x, int l, int r, int ql, int qr){
    if (ql <= l && qr >= r){
        return mx[x];
    }
    int ret = 0;
    int mid = (l + r) / 2;
    if (ql <= mid){
        ret = max(ret, query(x<<1, l, mid, ql, qr));
    }
    if (qr > mid){
        ret = max(ret, query(x<<1|1, mid+1, r, ql, qr));
    }
    return ret;
}
void update(int x, int l, int r, int pos, int val){
    if (l == r) {
        mx[x] = val;
        return;
    }
    int mid = (l + r) / 2;
    if (pos <= mid) update(x<<1, l, mid, pos, val);
    else update(x<<1|1, mid+1, r, pos, val);
    pull(x);
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    while(cin >> n >> m){
        build(1, 1, n);
        while(m --){
            cin >> c;
            if (c == 'Q'){
                int a, b;
                cin >> a >> b;
                cout << query(1, 1, n, a, b)<<endl;
            }else if (c == 'U'){
                int a, b;
                cin >> a >> b;
                update(1, 1, n, a, b);
            }
        }
    }
}
```