hdu1754经典
/*hdu1754满二叉树递推式处理线段树,输入输出优化外挂*/
#include<cstdio>
const int M=262144;
int max(int a,int b){return a>b?a:b;}
int tr[16],n,m,i,a,b,c,N;
inline bool scan_ud(int &num) //输入函数,以字符的形式输入
{
char in;
in = getchar();
if(in == EOF) return false;
while(in < '0' || in > '9') in = getchar();
num = in - '0';
while(in = getchar(), in >= '0' && in <= '9')num *= 10, num += in - '0';
return true;
}
inline void put(int x)//输出函数,以字符的形式输出
{
if(x == 0){
putchar('0');
return;
}
char s[20];
int bas = 0;
for(;x;x/=10)
s[bas++] = x%10+'0';
for(;bas--;)
putchar(s[bas]);
return;
}
int main()
{
while(scan_ud(n))
{
scan_ud(m);
N=M;
while(n<N)
N>>=1;
N<<=1;
for(i=N+1;i<=N+n;i++)
scan_ud(tr[i]);
for(i=N-1;i>=1;i--)
tr[i]=max(tr[i+i],tr[i+i+1]);
for(i=1;i<=m;i++)
{
c=getchar();scan_ud(a);scan_ud(b);
if (c=='U')
for(tr[a+=N]=b,a>>=1;a;a>>=1)
tr[a]=max(tr[a+a],tr[a+a+1]);
if (c=='Q')
{
int ans=0;
for(a+=N-1,b+=N+1;a^b^1;a>>=1,b>>=1)
{
if (~a&1)
ans=max(ans,tr[a^1]);
if (b&1)
ans=max(ans,tr[b^1]);
}
put(ans);putchar('\n');
}
}
}
return 0;
}