#include<iostream>
#include<math.h>
#include<stdio.h>
using namespace std;
const int maxn=200000+100;
int a[maxn];
struct Node{
int data;
int left,right;
};
Node b[maxn*10];
int max(int x,int y){
return x>y ? x:y;
}
//建立二叉树
void BuidTree(int root,int first,int last){
b[root].left=first;
b[root].right=last;
if(first==last){
b[root].data=a[first];
return;
}
int temp=(first+last)/2;
BuidTree(root*2,first,temp);
BuidTree(root*2+1,temp+1,last);
b[root].data=max(b[root*2].data,b[root*2+1].data);
}
//查找节点
int look(int root,int first,int last){
if(last<b[root].left || first >b[root].right)
return 0;
if(first<=b[root].left && last>=b[root].right)
return b[root].data;
int p1=look(root*2,first,last);
int p2=look(root*2+1,first,last);
return max(p1,p2);
}
//节点的更新
void update(int root ,int i,int x){
if (i < b[root].left || b[root].right < i)
return ;
if(b[root].left == b[root].right){
b[root].data=x;
return;
}
int t=(b[root].left+b[root].right)/2;
if(i<=t)
update(root*2,i,x);
else
update(root*2+1,i,x);
b[root].data=max(b[root*2].data,b[root*2+1].data);
}
int main(){
int N,M;
while(scanf("%d%d",&N,&M)!=EOF){
for(int i=1;i<=N;i++)
scanf("%d",&a[i]);
BuidTree(1,1,N);
while(M--){
getchar();
char c;
int A,B;
scanf("%c%d%d",&c,&A,&B);
if(c=='Q')
printf("%d\n",look(1,A,B));
else
update(1,A,B);
}
}
return 0;
}
杭电1754
最新推荐文章于 2020-10-10 06:12:06 发布