题目大意:中文题
解题思路:模版题
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 200000 << 2;
int S[maxn], L[maxn], R[maxn];
int num[maxn];
void build(int u, int l, int r) {
if( l == r) {
S[u] = num[l];
L[u] = l;
R[u] = l;
return ;
}
int mid = (l + r) / 2;
build(2*u,l,mid);
build(2*u+1,mid+1,r);
S[u] = max(S[2*u],S[2*u+1]);
L[u] = l;
R[u] = r;
}
void modify(int id, int x, int u) {
if(L[x] == id && R[x] == id) {
S[x] = u;
return ;
}
int mid = (L[x] + R[x]) / 2;
if(id <= mid)
modify(id,2*x,u);
else
modify(id,2*x+1,u);
S[x] = max(S[2*x],S[2*x+1]);
}
int search(int s, int e, int u) {
if(L[u] >= s && R[u] <= e)
return S[u];
int mid = (L[u] + R[u]) / 2;
if(s >= mid + 1)
return search(s,e,2*u+1);
else if(e <= mid)
return search(s,e,2*u);
else
return max(search(s,e,2*u),search(s,e,2*u+1));
}
int main() {
int N, M;
int test;
while(scanf("%d%d",&N,&M) == 2) {
for(int i = 1; i <= N; i++)
scanf("%d",&num[i]);
build(1,1,N);
getchar();
int s, e;
char c;
for(int i = 0; i < M; i++) {
scanf("%c%d%d",&c,&s,&e);
getchar();
if(c == 'Q')
printf("%d\n",search(s,e,1));
else
modify(s,1,e);
}
}
return 0;
}