博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 1754 I hate it
阅读量:4350 次
发布时间:2019-06-07

本文共 1340 字,大约阅读时间需要 4 分钟。

最裸的线段树单点替换,区间查找最大值。

#include 
#include
using namespace std;#define M ((L+R)>>1)#define lson rt<<1,L,M#define rson rt<<1|1,M+1,R#define root 1,1,N#define max(a,b) ((a>b)?a:b)const int maxn = 200001;int maxv[maxn << 2],ql,qr,tar,v,val[maxn];inline void pushup(int rt) { maxv[rt] = max(maxv[rt<<1],maxv[rt<<1|1]);}void build(int rt,int L,int R) { if(L == R) maxv[rt] = val[L]; else { build(lson); build(rson); pushup(rt); }}void update(int rt,int L,int R) { if(L == R) maxv[rt] = v; else { if(tar <= M) update(lson); if(tar > M) update(rson); pushup(rt); }}int query(int rt,int L,int R) { if(ql <= L && qr >= R) return maxv[rt]; int lv = -INT_MAX,rv = -INT_MAX; if(ql <= M) lv = query(lson); if(qr > M) rv = query(rson); return max(lv,rv);}int main() { int N,m; char cmd; while(~scanf("%d%d",&N,&m)) { for(int i = 1;i <= N;i++) scanf("%d",val + i); build(root); for(int i = 1;i <= m;i++) { scanf(" %c",&cmd); if(cmd == 'Q') { scanf("%d%d",&ql,&qr); printf("%d\n",query(root)); } else { scanf("%d%d",&tar,&v); update(root); } } } return 0;}

转载于:https://www.cnblogs.com/rolight/p/3468089.html

你可能感兴趣的文章
js 选取子节点时去除非IE浏览器的换行符
查看>>
javascript是一朵奇葩
查看>>
Mycat入门教程
查看>>
关于"无法解析的外部符号"问题的解决
查看>>
【JavaScript】【译】编写高性能JavaScript
查看>>
【随笔】入行必读:互联网行业薪酬等级
查看>>
Android使用开源框架加载图片
查看>>
CLR是怎么加载到内存的?
查看>>
fckeditor
查看>>
backbone.js
查看>>
python类的特殊成员变量
查看>>
sublime text3最新版本注册码(build 3143)
查看>>
linux使用技巧
查看>>
必背公式及常数
查看>>
利用CSS、JavaScript及Ajax实现图片预加载的三大方法
查看>>
EntityManager的merge()方法
查看>>
Spring中线程池的应用
查看>>
前端登录jq图形验证码
查看>>
软件设计
查看>>
Hadoop各种进程的配置文件及其位置说明
查看>>