zoukankan      html  css  js  c++  java
  • 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
    ",query(x,y,1,1,n));
    			}
    			else
    				update(x,y,1,1,n);
    		}
    		 
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    git fetch, merge, pull, push需要注意的地方
    记录一次数据库驱动配置引发的惨案
    IntelliJ Idea 常用快捷键列表
    数据库设计范式
    windows下mysql服务常用操作
    开源协议知多少
    Error creating bean
    Validation failed for query for method
    Not supported for DML operations
    404
  • 原文地址:https://www.cnblogs.com/starve/p/10822080.html
Copyright © 2011-2022 走看看