• HDU 1754 I Hate It 线段树


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

    还是单点更新的...基本没什么问题...

    /********************* Template ************************/
    #include <set>
    #include <map>
    #include <list>
    #include <cmath>
    #include <ctime>
    #include <deque>
    #include <queue>
    #include <stack>
    #include <bitset>
    #include <cstdio>
    #include <string>
    #include <vector>
    #include <cassert>
    #include <cstdlib>
    #include <cstring>
    #include <sstream>
    #include <fstream>
    #include <numeric>
    #include <iomanip>
    #include <iostream>
    #include <algorithm>
    #include <functional>
    using namespace std;
    #define BUG         cout<<" BUG! "<<endl;
    #define LINE        cout<<" ------------------ "<<endl;
    #define FIN         freopen("in.txt","r",stdin);
    #define lson        l,m,rt<<1
    #define rson        m+1,r,rt<<1|1
    #define FOR(i,a,b)  for(int i = a ; i < b ; i++)
    #pragma comment     (linker,"/STACK:102400000,102400000")
    template<class T> inline T L(T a)       {return (a << 1);}
    template<class T> inline T R(T a)       {return (a << 1 | 1);}
    template<class T> inline T lowbit(T a)  {return (a & -a);}
    template<class T> inline T Mid(T a,T b) {return ((a + b) >> 1);}
    template<class T> inline T gcd(T a,T b) {return b ? gcd(b,a%b) : a;}
    template<class T> inline T lcm(T a,T b) {return a / gcd(a,b) * b;}
    template<class T> inline T Min(T a,T b) {return a < b ? a : b;}
    template<class T> inline T Max(T a,T b) {return a > b ? a : b;}
    template<class T> inline T Min(T a,T b,T c)     {return min(min(a,b),c);}
    template<class T> inline T Max(T a,T b,T c)     {return max(max(a,b),c);}
    template<class T> inline T Min(T a,T b,T c,T d) {return min(min(a,b),min(c,d));}
    template<class T> inline T Max(T a,T b,T c,T d) {return max(max(a,b),max(c,d));}
    template<class T> inline void mem(T &a,int b)   {memset(a,b,sizeof(a));}
    template<class T> inline T exGCD(T a, T b, T &x, T &y){ //
        if(!b) return x = 1,y = 0,a;
        T res = exGCD(b,a%b,x,y),tmp = x;
        x = y,y = tmp - (a / b) * y;
        return res;
    }
    typedef long long LL;    typedef unsigned long long ULL;
    //typedef __int64 LL;      typedef unsigned __int64 ULL;
    const LL LINF       = 1LL << 60;
    const int MOD       = 1000000007;
    const int INF       = 0x7fffffff;
    const int MAXN      = 200050;
    const double EPS    = 1e-8;
    const double DINF   = 1e15;
    const double PI     = acos(-1.0);
    
    /*********************   By  F   *********************/
    int sMax[MAXN<<2];
    void pushup(int rt){
        sMax[rt] = max(sMax[L(rt)],sMax[R(rt)]);
    }
    void build(int l,int r,int rt){
        if(l == r) {
            scanf("%d",&sMax[rt]);
            return;
        }
        int m = Mid(l,r);
        build(lson);
        build(rson);
        pushup(rt);
    }
    void update(int pos,int val,int l,int r,int rt){
        if(l == r){
            sMax[rt] = val;
            return ;
        }
        int m = Mid(l,r);
        if(pos <= m) update(pos,val,lson);
        else update(pos,val,rson);
        pushup(rt);
    }
    int query(int L,int R,int l,int r,int rt){
        if(L <= l && r <= R) return sMax[rt];
        int m = Mid(l,r);
        int ret = 0;
        if(L <= m) ret = max(ret,query(L,R,lson));
        if(R > m) ret = max(ret,query(L,R,rson));
        return ret;
    }
    int main(){
        //FIN;
        int T,n,m,i,j;
        char op[5];
        while(~scanf("%d%d",&n,&m)){
            build(1,n,1);
            while(m--){
                scanf("%s%d%d",op,&i,&j);
                if(op[0] == 'Q') printf("%d
    ",query(i,j,1,n,1));
                if(op[0] == 'U') update(i,j,1,n,1);
            }
        }
        return 0;
    }
  • 相关阅读:
    耗油
    [深入Python]Alex Martelli的Borg类
    Python Frame objects 和Traceback objects
    2012美国汽车销量排行
    Python中统计函数的运行耗时
    Python显示函数的调用者
    Python的内置函数map
    [深入Python]简单事情复杂化:Python计算阶乘
    Solaris查看线程
    VVR常用操作
  • 原文地址:https://www.cnblogs.com/Felix-F/p/3335206.html
Copyright © 2020-2023  润新知