hdu 1754 线段树模板题

时间:2023-12-06 16:31:56

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1754

 #include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <queue>
#include <vector> #define maxn 230050
#define lson l,mid,u<<1
#define rson mid+1,r,u<<1|1
using namespace std; const int INF = 0x3f3f3f; int seg[maxn<<]; int Push_UP(int u){
seg[u] = max(seg[u<<],seg[u<<|]); //****这个地方 u<<1|1 不能换为 u << 1 +1
}
void build(int l,int r,int u){
if(l == r){
scanf("%d",&seg[u]);
return;
}
int mid = (l + r)/;
build(lson);
build(rson);
Push_UP(u);
}
void Update(int loc,int num,int l,int r,int u){
if(l == r){ // 这个地方要注意!!
seg[u] = num;
return;
}
int mid = (l + r)/;
if(loc <= mid) Update(loc,num,lson);
else Update(loc,num,rson);
Push_UP(u);
}
int Query(int L,int R,int l,int r,int u){
if(L <= l && r <= R){
return seg[u];
}
int ret = ;
int mid = (l + r)/;
if(L <= mid) ret =max(ret,Query(L,R,lson));
if(R > mid) ret =max(ret,Query(L,R,rson));
return ret;
}
int main()
{
if(freopen("input.txt","r",stdin)== NULL) {printf("Error\n"); exit();}
int N,M;
while(cin>>N>>M){
build(,N,);
while(M--){
char query[];
int l,r;
scanf("%s%d%d",query,&l,&r);
if(query[] == 'U') Update(l,r,,N,);
else{
int ans = Query(l,r,,N,);
printf("%d\n",ans);
}
}
}
}