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

    单点修改,区间最值的标程,没什么好说的。

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<algorithm>
     5 #include<cmath>
     6 using namespace std;
     7 
     8 #define lson l,m,root<<1
     9 #define rson m+1,r,root<<1|1
    10 const int MAXN=200000+50;
    11 int n,m;
    12 int maxn[MAXN*4];
    13 
    14 void pushUP(int root)
    15 {
    16     maxn[root]=max(maxn[root<<1],maxn[root<<1|1]);
    17 }
    18 
    19 void build(int l,int r,int root)
    20 {
    21     if (l==r)
    22     {
    23         scanf("%d",&maxn[root]);
    24         return;
    25     }
    26     int m=(l+r)>>1;
    27     build(lson);
    28     build(rson);
    29     pushUP(root);
    30 }
    31 
    32 void update(int p,int delta,int l,int r,int root)
    33 {
    34     if (l==r)
    35     {
    36         maxn[root]=delta;
    37         return;
    38     }
    39     int m=(l+r)>>1;
    40     if (p<=m) update(p,delta,lson);
    41     if (p>m) update(p,delta,rson);
    42     pushUP(root);
    43 }
    44 
    45 int query(int L,int R,int l,int r,int root)
    46 {
    47     if (l>=L && r<=R)
    48     {
    49         return maxn[root];
    50     }
    51     int m=(l+r)>>1,res=-1;
    52     if (L<=m) res=max(res,query(L,R,lson));
    53     if (R>m) res=max(res,query(L,R,rson));
    54     pushUP(root);
    55     return res;
    56 }
    57 
    58 int main()
    59 {
    60     while (scanf("%d%d",&n,&m)!=EOF)
    61     {
    62         build(1,n,1);
    63         for (int i=0;i<m;i++)
    64         {
    65             getchar();
    66             char c;
    67             int a,b;
    68             scanf("%c%d%d",&c,&a,&b);
    69             if (c=='Q') cout<<query(a,b,1,n,1)<<endl;
    70             if (c=='U') update(a,b,1,n,1);
    71         }
    72     }
    73     return 0;
    74 }
  • 相关阅读:
    洛谷1020导弹拦截
    bzoj2467生成树
    qhfl-2 ContentType组件
    qhfl-1 跨域
    drf8 解析器
    drf7 分页组件
    drf6 权限和频率控制组件
    Flex 布局教程:语法篇
    2017年最新cocoapods安装教程(解决淘宝镜像源无效以及其他源下载慢问题)
    git命令行
  • 原文地址:https://www.cnblogs.com/iiyiyi/p/4856685.html
Copyright © 2011-2022 走看看