zoukankan      html  css  js  c++  java
  • hdu1754I Hate It

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1754

    单点更新,查找区间最大值。

     1 #include<cstdio>
     2 #include<iostream>
     3 #define lson l,m,rt<<1
     4 #define rson m+1,r,rt<<1|1
     5 using namespace std;
     6 const int maxn=200010;
     7 int f[maxn<<2];
     8 inline pushup(int rt)
     9 {
    10     f[rt]=max(f[rt<<1],f[rt<<1|1]);
    11 }
    12 
    13 void build(int l,int r,int rt)
    14 {
    15     if(l==r)
    16     {
    17         scanf("%d",&f[rt]);
    18         return ;
    19     }
    20     int m=(l+r)>>1;
    21     build(lson);
    22     build(rson);
    23     pushup(rt);
    24 }
    25 
    26 void update(int p,int sc,int l,int r,int rt)
    27 {
    28     if(l==r) {
    29         f[rt]=sc;
    30         return;
    31     }
    32     int m=(l+r)>>1;
    33     if(p<=m) update(p,sc,lson);
    34     else update(p,sc,rson);
    35     pushup(rt);
    36 }
    37 
    38 int query(int L,int R,int l,int r,int rt)
    39 {
    40     if(L<=l&&r<=R) return f[rt];
    41     int m=(l+r)>>1;
    42     int ans=-1;
    43     if(L<=m) ans=max(ans,query(L,R,lson));
    44     if(R>m) ans=max(ans,query(L,R,rson));
    45     return ans;
    46 }
    47 
    48 int main()
    49 {
    50     int n,m,a,b;
    51     while(scanf("%d%d",&n,&m)!=EOF)
    52     {
    53         build(1,n,1);
    54         char s[2];
    55         while(m--)
    56         {
    57             scanf("%s%d%d",s,&a,&b);
    58             if(s[0]=='Q') printf("%d
    ",query(a,b,1,n,1));
    59             else update(a,b,1,n,1);
    60         }
    61 
    62     }
    63     return 0;
    64 }
  • 相关阅读:
    CSS躬行记(9)——网格布局
    CSS躬行记(8)——裁剪和遮罩
    CSS躬行记(7)——合成
    CentOS 系统目录解析
    Linux 命令快捷键
    秒的精确度
    Oracle和mysql中装逼dual表的用途介绍
    mysql 的mgr集群
    ansible笔记
    cygwin
  • 原文地址:https://www.cnblogs.com/yijiull/p/6619091.html
Copyright © 2011-2022 走看看