hdu 1754

在写的时候加了判断询问位置先后的swap结果wa了快十次了,不知道为什么;

http://acm.hdu.edu.cn/showproblem.php?pid=1754

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
typedef long long ll;
const int M=2e5+5;
const int inf=0x3f3f3f3f;
int tree[M<<2];
int ma(int a,int b){
	return a>b?a:b;
}

void up(int root){
	tree[root]=ma(tree[root<<1],tree[root<<1|1]);
}
void build(int root,int l,int r){
	if(l==r){
		scanf("%d",&tree[root]);
		return ;
	}
	int midd=(l+r)>>1;
	build(root<<1,l,midd);
	build(root<<1|1,midd+1,r);
	up(root);
}
void update(int p,int x,int root,int l,int r){
	if(l==r){
		tree[root]=x;
		return ;
	}
	int midd=(l+r)>>1;
	if(p<=midd)
		update(p,x,root<<1,l,midd);
	else
		update(p,x,root<<1|1,midd+1,r);
	up(root);
}
int query(int L,int R,int root,int l,int r){
	if(L<=l&&r<=R){
		return tree[root];
	}
	int midd=(l+r)>>1;
	int ans=0;
	if(L<=midd)
		ans=max(ans,query(L,R,root<<1,l,midd));
	if(R>midd)
		ans=max(ans,query(L,R,root<<1|1,midd+1,r));
	return ans;
}
char s[2];
int main(){
	int m,n;
	while(scanf("%d%d",&n,&m)!=EOF){
		memset(tree,0,sizeof(tree));
		build(1,1,n);
		while(m--){
			int x,y;
			scanf("%s%d%d",s,&x,&y);

			if(s[0]=='Q'){
				printf("%d\n",query(x,y,1,1,n));
			}
			else
				update(x,y,1,1,n);
		}
		 
	}
	return 0;
}

  

posted @ 2019-05-06 21:04  starve_to_death  阅读(117)  评论(0编辑  收藏  举报