• hdu 1754 I Hate It 线段树 点改动


    // hdu 1754 I Hate It 线段树 点改动
    //
    // 不多说,裸的点改动
    //
    // 继续练
    #include <algorithm>
    #include <bitset>
    #include <cassert>
    #include <cctype>
    #include <cfloat>
    #include <climits>
    #include <cmath>
    #include <complex>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <ctime>
    #include <deque>
    #include <functional>
    #include <iostream>
    #include <list>
    #include <map>
    #include <numeric>
    #include <queue>
    #include <set>
    #include <stack>
    #include <vector>
    #define ceil(a,b) (((a)+(b)-1)/(b))
    #define endl '
    '
    #define gcd __gcd
    #define highBit(x) (1ULL<<(63-__builtin_clzll(x)))
    #define popCount __builtin_popcountll
    typedef long long ll;
    using namespace std;
    const int MOD = 1000000007;
    const long double PI = acos(-1.L);
    
    template<class T> inline T lcm(const T& a, const T& b) { return a/gcd(a, b)*b; }
    template<class T> inline T lowBit(const T& x) { return x&-x; }
    template<class T> inline T maximize(T& a, const T& b) { return a=a<b?b:a; }
    template<class T> inline T minimize(T& a, const T& b) { return a=a<b?a:b; }
    
    const int maxn = 8 * 1e5 +8;
    int maxv[maxn];
    int n,m;
    const int inf = 0x7f7f7f7f;
    void build(int root,int L,int R){
    	if (L==R){
    		scanf("%d",&maxv[root]);
    		return ;
    	}
    	int M = L + ( R - L ) / 2;
    	build(root*2,L,M);
    	build(root*2+1,M+1,R);
    	maxv[root] = max(maxv[root*2],maxv[root*2+1]);
    }
    int p,v;
    
    void update(int root,int L,int R){
    	if (L==R){
    		maxv[root] = v;
    		return ;
    	}
    	int M = L + ( R - L ) / 2;
    	if (p<=M)	update(root*2,L,M);
    	else update(root*2+1,M+1,R);
    	maxv[root] = max(maxv[root*2],maxv[root*2+1]);
    }
    
    int query(int root,int ql,int qr,int L,int R){
    	if (ql<=L && R<=qr){
    		return maxv[root];
    	}
    	int M = L + ( R - L) / 2; 
    	int ans = 0;
    	if (ql<=M)	ans = max(ans,query(root*2,ql,qr,L,M));
    	if (M<qr)	ans = max(ans,query(root*2+1,ql,qr,M+1,R));
    	return ans;
    }
    
    void init(){
    	build(1,1,n);
    	char s[3];
    	for (int i=0;i<m;i++){
    		int x,y;
    		scanf("%s%d%d",s,&x,&y);
    		if (s[0]=='Q'){
    			printf("%d
    ",query(1,x,y,1,n));
    		}else {
    			p = x;
    			v = y;
    			update(1,1,n);
    		}
    	}
    }
    
    
    
    int main() {
    //	freopen("G:\Code\1.txt","r",stdin);
    	while(scanf("%d%d",&n,&m)!=EOF){
    		init();
    	}
    	return 0;
    }
    

  • 相关阅读:
    图片处理连环画特效
    卡片翻页算法
    android 自定义属性
    android 中捕获全局异常
    c++ 学习笔记
    图片怀旧特效处理
    Linux 网络配置
    指针参数传递
    python 读写文件
    PopupWindow 点击外面取消
  • 原文地址:https://www.cnblogs.com/cxchanpin/p/6944275.html
Copyright © 2020-2023  润新知