<span>HDU1754 I Hate It(线段树基础题单节点更新区间查询)</span>

这题用树状数组写要简单很多,因为我学习线段树,找了这个题入门。。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <queue>
#include <cmath>
#include <algorithm>
using namespace std;
#define M 200005
#define ls node<<1,l,m
#define rs node<<1|1,m+1,r
int n,m,tree[M*4];
void buildtree(int node,int l,int r)
{
    if(l==r) scanf("%d",&tree[node]);
    else
    {
        int m=(l+r)>>1;
        buildtree(ls);
        buildtree(rs);
        tree[node]=max(tree[node<<1],tree[node<<1|1]);
    }
}
int query(int node,int l,int r,int L,int R)
{
    if(L<=l&&r<=R) return tree[node];
    int p=0,m=(l+r)>>1;
    if(m>=L) p=query(ls,L,R);
    if(m<R) p=max(p,query(rs,L,R));
    return p;
}
void update(int node,int l,int r,int ind,int add)
{
    if(l==r) tree[node]=add;
    else
    {
        int m=(l+r)>>1;
        if(m>=ind) update(ls,ind,add);
        else update(rs,ind,add);
        tree[node]=max(tree[node<<1],tree[node<<1|1]);
    }
}
int main()
{
    //freopen("in.txt","r",stdin);
    while(~scanf("%d%d",&n,&m))
    {
        buildtree(1,1,n);
        char s[2];
        int a,b;
        while(m--)
        {
            scanf("%s%d%d",s,&a,&b);
            if(s[0]=='Q') printf("%d\n",query(1,1,n,a,b));
            else update(1,1,n,a,b);
        }
    }
    return 0;
}

 

全部评论

相关推荐

家人们,我现在真的好纠结。我是26届的,目前还没有实习过。我现在的情况是,想参加秋招,但是感觉自己的简历特别空,没有实习经历会不会秋招直接凉凉啊?可我又听说现在很多公司对26届实习生也不太感冒,说什么不确定性大。而且我最近在准备考公,时间上也有点冲突。要是把时间花在实习上,备考时间就少了。但要是不实习,又怕以后就业有问题😫有没有懂行的友友帮我分析分析:26届现在不实习,秋招找工作真的会很难吗?考公和实习该怎么平衡啊?如果现在不实习,考完公再去找实习还来得及吗?真的太焦虑了,希望大家能给我点建议🙏
小破站_程序员YT:我可能和大家的观点不一样。人的精力是有限的,不能既要还要。你又想实习又想考公最后又要秋招上岸,我觉得哪有那么多的选择。你如果想考上岸,那就全力以赴。如果想秋招上岸,就继续投实习,投没了,就继续准备秋招,秋招不行继续春招。别到最后,考公没上岸,觉得是花了时间浪费在找实习上了, 秋招没上岸,觉得是浪费时间准备考公去了。我是认为很难说可以去平衡 不喜勿喷,可以叫我删除
点赞 评论 收藏
分享
06-12 16:23
已编辑
小米_软件开发(准入职员工)
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务