【题意】给定区间求最大值

【分析】线段树单点更新

【代码】

#include<cstdio>
#include<iostream>
using namespace std;
const int maxn=1<<21;
const int INF=0x3fffffff;
int Max=0;
int mid;
struct Node
{
int l,r;//左孩子,右孩子
int value;
}N[maxn];
int p[200005];//记录标号
void build(int i,int left ,int right)//区间[left,right],节点标号i
{
N[i].l=left;
N[i].r=right;
N[i].value=0;
if(left==right)
{
p[left]=i;
return;
}
mid=(left+right)>>1;
build(i<<1,left,mid);
build(1+(i<<1),mid+1,right);
}
void update(int i)//从下往上更新单节点
{
if(i==1) return ;
int pi=i/2;
int left=pi<<1;
int right=(pi<<1)+1;
N[pi].value=max(N[left].value,N[right].value);
update(i/2);
}
void query(int i,int left,int right)//从上往下查询节点
{
if(N[i].l==left&&N[i].r==right)
{
Max=max(N[i].value,Max);
return;
}
i<<=1;
if(N[i].r>=left&&N[i].r>=right) query(i,left,right);
else if(N[i].r>=left&&N[i].r<=right) query(i,left,N[i].r);
i++;
if(N[i].l<=right&&N[i].l<=left) query(i,left,right);
else if(N[i].l<=right&&N[i].l>=left) query(i,N[i].l,right);
}
int main (void)
{
int n,m;
int A,B;
char c[2];
while(scanf("%d%d",&n,&m)==2)
{
build(1,1,n);
for(int i=1;i<=n;i++)
{
scanf("%d",& N[p[i]].value);
update(p[i]);
}
for(int i=1;i<=m;i++)
{
scanf("%s%d%d",c,&A,&B);
if(c[0]=='Q')
{
Max=0;
query(1,A,B);
printf("%d\n",Max);
}
else
{
N[p[A]].value=B;
update(p[A]);
}
}
}
return 0;
}

HDU 1754_I Hate It的更多相关文章

  1. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  2. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  3. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  4. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  5. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  6. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

  7. hdu 4481 Time travel(高斯求期望)(转)

    (转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...

  8. HDU 3791二叉搜索树解题(解题报告)

    1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...

  9. hdu 4329

    problem:http://acm.hdu.edu.cn/showproblem.php?pid=4329 题意:模拟  a.     p(r)=   R'/i   rel(r)=(1||0)  R ...

随机推荐

  1. ES3之bind方法的实现模拟

    扩展Function原型方法,此处用myBind来模拟bind实现 Function.prototype.myBind = function(o /*,args*/){       //闭包无法获取t ...

  2. 《Hadoop高级编程》之为Hadoop实现构建企业级安全解决方案

    本章内容提要 ●    理解企业级应用的安全顾虑 ●    理解Hadoop尚未为企业级应用提供的安全机制 ●    考察用于构建企业级安全解决方案的方法 第10章讨论了Hadoop安全性以及Hado ...

  3. 解决jquery与其他库的冲突

    1.jquery在其他库之后导入 第一种: jQuery.noConflict();//将变量$的控制权限交给其他类库,即将$的控制权让渡给其他类库 jQuery(function(){ jQuery ...

  4. asp IIS网站的配置(Win7下启用IIS7配置ASP运行环境)

    其实win7下的IIS7配置过程是非常简单的.下面让seo博客来详细的介绍一下win7下配置IIS7环境运行ASP网站的方法,以供初接触者参考   第一次在windows7下配置IIS,虽然有丰富的x ...

  5. SQL Server中行列转置方法

    PIVOT用于将列值旋转为列名(即行转列),在SQL Server 2000可以用聚合函数配合CASE语句实现 PIVOT的一般语法是:PIVOT(聚合函数(列) FOR 列 in (…) )AS P ...

  6. vs2015 qt5.8新添加文件时出现“无法找到源文件ui.xxx.h”

    转载请注明出处:http://www.cnblogs.com/dachen408/p/7147135.html vs2015 qt5.8新添加文件时出现“无法找到源文件ui.xxx.h” 暂时解决版本 ...

  7. linux查看内核版本和发行版本号

    1.查看Linux内核版本号:1.1 uname -r #查看当前linux系统的内核版本号显示举例:2.6.21-1.3194.fc71.2 uname -a #可以查看包括内核版本号.机器硬件信息 ...

  8. css 样式渲染

     1.文字过长时,自动换行

  9. fabric的安装

    https://blog.csdn.net/lepton126/article/details/79148027

  10. pycharm connect to github

    这位同学写得非常详细,推荐 http://www.cnblogs.com/feixuelove1009/p/5955332.html#undefined