话说题目不是只有一组数据吗?
这个题目我改了好久,,,,后来发下错在,,查询的时候错了,,,但还是很爽啊。AC。
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cstdlib>
using namespace std;
#define maxn 200005
#define inf 0x3f3f3f
int a[maxn*8];
int b[maxn*4];
void build_tree(int node,int l,int r)
{
int mid=l+(r-l)/2;
if(l==r) {a[node]=b[l];return ;}
build_tree(node*2,l,mid);
build_tree(node*2+1,mid+1,r);
a[node]=max(a[node*2],a[node*2+1]);
return ;
}
int x,y;
int find_max(int root, int l,int r)
{
int ans=0x80000000;
int mid=l+(r-l)/2;
if(x<=l&&y>=r) return a[root];//这里我就是错了。。。留个纪念
if(x<=mid) ans=max(ans,find_max(root*2,l,mid));
if(y>mid) ans=max(ans,find_max(root*2+1,mid+1,r));
return ans;
}
void update(int root,int l,int r)
{
int mid=l+(r-l)/2;
if(l==r) {a[root]=y; return ;}
if(x<=mid) update(root*2,l,mid);
else update(root*2+1,mid+1,r);
a[root]=max(a[root*2],a[root*2+1]);
}
int main()
{
int n,m;
// freopen("in.txt","r",stdin);
char t[20];
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(a,0,sizeof(a));
for(int i=1;i<=n;i++)
{
scanf("%d",&b[i]);
}
build_tree(1,1,n);
while(m--)
{
scanf("%s%d%d",&t,&x,&y);
if(t[0]=='Q')
{
if(x>y)
{
int temp=x;
x=y;
y=temp;
}
printf("%d\n",find_max(1,1,n));
}
if(t[0]=='U')
{
update(1,1,n);
}
}
}
return 0;
}