博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU - 1754 线段树
阅读量:6999 次
发布时间:2019-06-27

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

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define M 200000#define inf 0x3f3f3f3ftypedef long long ll;using namespace std;struct Data{ int max; int left, right;}tree[M*4];int n, m;int ans;int x, y;char ch;void built(int l,int r,int k) { tree[k].left = l, tree[k].right = r; if (l == r) { scanf("%d", &tree[k].max); return; } int mid = (l + r) / 2; built(l, mid,k*2); built(mid + 1, r, k * 2 + 1); tree[k].max = max(tree[k * 2].max, tree[k * 2 + 1].max);}void search(int k) { if (tree[k].left >= x && tree[k].right <= y) { ans = max(ans, tree[k].max); return; } int mid = (tree[k].left + tree[k].right) / 2; if (x <= mid) search(k * 2); if(y>mid) search(k * 2 + 1);}void change_inv(int k) { if (tree[k].left == tree[k].right) { tree[k].max = y; return; } int mid = (tree[k].left + tree[k].right) / 2; if (x <= mid) change_inv(k * 2); else change_inv(k * 2 + 1); tree[k].max = max(tree[k * 2].max, tree[k * 2 + 1].max);}int main() { while (scanf("%d%d",&n,&m)!=EOF){ built(1, n, 1); while (m--){ cin >> ch; scanf("%d%d", &x, &y); if(ch=='Q'){ ans = 0; search(1); printf("%d\n", ans); } else { change_inv(1); } } } return 0;}

 

转载于:https://www.cnblogs.com/caibingxu/p/10777073.html

你可能感兴趣的文章
win7 远程桌面凭证不工作
查看>>
centos 启动多台zookeeper
查看>>
NASA研制3D食物打印机:原料或取自昆虫
查看>>
彭斌_无人机的发展与未来
查看>>
OpenSSLRSAWrapper
查看>>
Cocoa Application Start Sequence
查看>>
图像处理控件ImageGear for .NET教程如何为应用程序 添加DICOM功能(2)
查看>>
基于Video4Linux的视频采集模块开发(转)
查看>>
cookies,sessionStorage 和 localStorage 的区别
查看>>
android中Tab设计中:tab中的listview最下面一部分被tab遮盖的解决
查看>>
CentOS下编译php时的一些典型错误及解决办法.
查看>>
Hg Mercurial版本管理介绍
查看>>
redis
查看>>
开源项目学习方法
查看>>
block的使用
查看>>
使用Toolbar自定义布局的时候左边右边总有一点空间无法使用
查看>>
Photoshop 常用快捷键
查看>>
外观模式
查看>>
Extjs 4 grid修改某一行style
查看>>
background-position设置无效问题解决
查看>>