题目传送门:HDU 1754 - I Hate It
线段树:单点更新,区间求最值
AC Code:
//AcerGY
//#pragma comment (linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <cmath>
#define ll long long
#define BUG puts("BUG!")
#define ci(val) scanf("%d",&val)
#define pi(val) printf("%d\n",val)
#define clr(a,val) memset(a,val,sizeof(a))
#define lowbit(x) ((x)&(-x))
#define inf 0x3f3f3f3f
#define inf64 1LL<<60
#define PI acos(-1.0)
#define eps 1e-8
//Game Theory
#define P "First"
#define N "Second"
#define maxn 200000+10
#define mod 10009
using namespace std;
void readfile(char s[])
{
#ifndef ONLINE_JUDGE
freopen(s,"r",stdin);
#endif
}
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
int seg[maxn<<2];
int n,m;
void push(int root)
{
seg[root] = max(seg[root<<1],seg[root<<1|1]);
}
void build(int l,int r,int root)
{
if(l==r)
{
scanf("%d",&seg[root]);return;
}
int mid = (l+r)>>1;
build(lson);build(rson);
push(root);
}
void update(int pos,int val,int l,int r,int root)
{
if(l==r)
{
seg[root] = val;return;
}
int mid = (l+r)>>1;
if(pos<=mid)
update(pos,val,lson);
else
update(pos,val,rson);
push(root);
}
int query(int L,int R,int l,int r,int root)
{
int ans = 0;
if(L<=l && r<=R)
{
//printf("seg[%d]=%d\n",root,seg[root]);
return seg[root];
}
int mid = (l+r)>>1;
if(L<=mid)
ans = max(ans,query(L,R,lson));
if(R>mid)
ans = max(ans,query(L,R,rson));
return ans;
}
int main()
{
ios::sync_with_stdio(0);
readfile("1754.txt");
int T , cas = 1;
while(~scanf("%d%d",&n,&m))
{
build(1,n,1);
char op[2];int u,v;
while(m--)
{
scanf("%s%d%d",op,&u,&v);
if(op[0]=='U')
update(u,v,1,n,1);
else
printf("%d\n",query(u,v,1,n,1));
}
}
return 0;
}