zoukankan      html  css  js  c++  java
  • HDOJ1745 I hate it【线段树】

    Problem : 1754 ( I Hate It )     Judge Status : Accepted
    RunId : 5863027    Language : C    Author : qq1203456195

    #include <stdio.h>
    #include <stdlib.h>
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define maxn 200001
    int Max[maxn<<2];
    void build(int l,int r,int rt)
    {
        int m;
        if (l==r)
        {
            scanf("%d",&Max[rt]);
            return;
        }
        m=((l+r)>>1);
        build(lson);
        build(rson);
        Max[rt]=max(Max[rt<<1],Max[rt<<1|1]);
    }
    void update(int p,int updt,int l,int r,int rt)
    {
        int m;
        if(l==r)
        {
            Max[rt]=updt;
            return;
        }
        m=((l+r)>>1);
        if (p<=m)
            update(p,updt,lson);
        else
            update(p,updt,rson);
        Max[rt]=max(Max[rt<<1],Max[rt<<1|1]);
    }
    int query(int L,int R,int l,int r,int rt)
    {
        int m,ret=0,maxl,maxr;
        if (L<=l&&R>=r)
            return Max[rt];
        m=((l+r)>>1);
        if (R<=m)
            ret=query(L,R,lson);
        else
            if(L>m)
                ret=query(L,R,rson);
            else
            {
                maxl=query(L,m,lson);
                maxr=query(m+1,R,rson);
                ret=max(maxl,maxr);
            }
                
        return ret;
    }
    int main()
    {
        int n,a,b,m,i;
        char op[2];
        while (scanf("%d%d",&n,&m)!=EOF)
        {
            build(1,n,1);
            while (m--)
            {
                scanf("%s%d%d",op,&a,&b);
                if(op[0]=='Q')
                    printf("%d\n",query(a,b,1,n,1));
                else
                    if(op[0]=='U')
                        update(a,b,1,n,1);
            }
        }
        return 0;
    }
    字节跳动内推

    找我内推: 字节跳动各种岗位
    作者: ZH奶酪(张贺)
    邮箱: cheesezh@qq.com
    出处: http://www.cnblogs.com/CheeseZH/
    * 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

  • 相关阅读:
    docker 基础
    shell
    MySQL之MGR
    MySQL之读写分离
    MySQL主从复制
    MySQL之数据类型
    MySQL之索引与约束条件
    SQL语句进阶
    SQL语句初识
    Linux之MySQL安装
  • 原文地址:https://www.cnblogs.com/CheeseZH/p/2475489.html
Copyright © 2011-2022 走看看